WMI with WCF service - wcf

I am trying to enable and use WMI with a WCF service which i have, i have changed the configurations as per the link below.
http://msdn.microsoft.com/en-us/library/ms735120.aspx
http://msdn.microsoft.com/en-us/library/ms751442.aspx
<diagnostics wmiProviderEnabled="true" performanceCounters="All">
<messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true" />
</diagnostics>
I am using the WMI object browser to read the WMI data from AppDomainInfo. When I run the service directly from Visual Studio 2010, using the WMI object browser I am able to read the AppDomainInfo data and also modify it also the Logs are creation is working.
If I connect to the service using my ASP.Net application so that the service is accessed and now when I try to access the WMI data from WMI object browser, I get a error message saying no instance of the class AppDomainData.
How can the WMI data be accessed without running the WCF service from Visual studio. Is any other configuration am i missing.
Thanks

I had to add aspnet user to ServiceModel security in WMI control as aspnet_wp process runs under aspnet user. With this i was able to access the WMI data in WMI object browser.

Related

WCF / WebService to act as Listener for MQ Message?

Perhaps I am barking up the wrong tree - but I have a set of services (WebAPI and WCF) that use WebSphere MQ to interact with other systems.
This works without issue - until I now need to find a way of listening for messages on one of the queues.
Is this even possible, or do I need to go down the windows Service route?
You could write a Windows service that is continually calling MQ Get on the queue, and invokes a WCF service to process the message. Or you could write a trigger program (a console application) that MQ will launch for you when a message arrives, that invokes the WCF service.
I might be just better at googling than you are, but I seem to have found the answer here.
Seems you want to load the IBM binding configuration in you app.config
<extensions>
<bindingElementExtensions>
<add name="IBM.XMS.WCF.SoapJmsIbmTransportChannel"
type="IBM.XMS.WCF.SoapJmsIbmTransportBindingElementConfig, IBM.XMS.WCF, Version=7.5.0.0, Culture=neutral, PublicKeyToken=8c7c0be90afcd8ba"/>
</bindingElementExtensions>
</extensions>
Then you can add a WebSphere WCF binding config.
<bindings>
<customBinding>
<binding name="CustomBinding_WMQ">
<textMessageEncoding messageVersion="Soap11" />
<IBM.XMS.WCF.SoapJmsIbmTransportChannel />
</binding>
</customBinding>
</bindings>
Your problem can be broken down into two distinct elements:
How to integrate MQ with a WCF-supported transport
How to expose a WCF endpoint over this transport
To address the first issue, you should look at the MQ-MSMQ bridge which ships with Host Integration Server up to version 2009 (not R2), which allows you to have messages delivered to MQSeries queues forwarded to local MSMQs in windows. Although this feature is deprecated it's probably the easiest way if you have a MSDN license.
Another way of addressing this issue is to use BizTalk server which ships with a MQSeries adapter, though unless you're using BizTalk currently in your enterprise I would avoid.
The last way you could do this is to program directly against the MQSeries .NET client libraries or via the XMS client.
If you manage to solve the first issue then solving the second one is easy enough. You can expose one way WCF service operations over msmq transport by using the netMsmqBinding (for WCF on both ends), or msmqIntegrationBinding for clients using System.Messaging or native msmq COM libraries.
This in-effect acts as a listener service, with messages being handled by the service operation.
how to get connect with ibm websphere mq by using c#.net
Perhaps you could use the above answer and within that queue consumer app create a "Service Reference" to your WCF service.

Workflow Service (xamlx) using AppFabric not persisting

I installed Appfabric Hosting Services. I created a xamlx Workflow Service. The workflow service sends emails based on a user's schedule. The Appfabric Persistence was working, but I unknowingly must have changed something, because it stopped persisting in the Appfabric database. The Workflow Service still works as long as I don't do an iisreset, which makes sense because the workflow is hosted in IIS.
I uninstalled AppFabric and re-installed it. In my root web.config, the InstanceStore is defined:
<instanceStores>
<add name="defaultSqlPersistenceStore" provider="SqlPersistenceStoreProvider" connectionStringName="ApplicationServerWorkflowInstanceStoreConnectionString" />
</instanceStores>
And the connectionStringName is defined. When I go to IIS and select the web application, I select configure from the Manage WCF and WF Services, and go to the Workflow Persistence tab. I select SQL Server Workflow Persistence and the SQL Server store drop down list is empty. If I select the computer name on the right in IIS and click Configure to setup Workflow Persistence, the defaultSqlPersistenceStore from above is in the drop down list. But that still doesn't help my Workflow service. In my Workflow Service web.config, I have:
<behavior name="Scheduler">
<sqlWorkflowInstanceStore instanceCompletionAction="DeleteAll" instanceEncodingOption="GZip" instanceLockedExceptionAction="BasicRetry" connectionStringName="WorkflowPersistenceStore" hostLockRenewalPeriod="00:00:30" runnableInstancesDetectionPeriod="00:00:05" />
<workflowInstanceManagement authorizedWindowsGroup="AS_Administrators" />
<workflowUnhandledException action="AbandonAndSuspend" />
<workflowIdle timeToPersist="00:01:00" timeToUnload="00:01:00" />
</behavior>
I tried adding a store to the WF service web.config:
<microsoft.applicationServer>
<persistence>
<instanceStores>
<add name="storeA" provider="SqlPersistenceStoreProvider" connectionStringName="WorkflowPersistenceStore" />
</instanceStores>
</persistence>
</microsoft.applicationServer>
and I'm able to select it in IIS - Configure WCF and WF Services, but my WF Service still doesn't persist.
When I check the Persistence database tables, the WF Service isn't even registered. (SELECT * FROM [System.Activities.DurableInstancing].[ServiceDeploymentsTable]). When persistence was working, there was a record with the WF Service url.
Thanks in advance,
-jason

How to debug a WCF Service with an HTTP Context?

I need to debug a WCF service but it needs to have an HTTP Context.
Currently I have a solution with a WCF service web site, when I click on debug it starts up and then fires up an html page that contains no test form.
While the project is running I tried starting the wcftestclient manually, then provided the address of my service, it finds the service but when I invoke it, it bypasses the IIS layer (or development server), so the httpContext is null...
What is the correct way to debug a WCF service through an IIS context?
In WCF, the HttpContext is set to NULL by default and by design, even if the WCF service is hosted in IIS; after all, WCF is not ASP.NET.
If you actually do need an HttpContext, you need to turn it on separately, through config (web.config if you host in IIS, your self-host app's app.config otherwise):
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
and you need to specify that fact (that your service allows or even expects the ASP.NET compatibility mode) by putting this attribute on your service class (that implements the service contract):
[AspNetCompatibilityRequirements
(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
public class MyWCFService : IMyWCFService
{
......
}
RequirementsMode=Allowed just simply allows the ASP.NET compatibility mode, while RequirementsMode=Required actually requires is and will not work without it.
Once you do that, you should get your HttpContext.Current when you attach your debugger to the IIS worker process.
Marc
You will have to attach your debugger (Visual Studio) to the IIS service process.
In Visual Studio, go to Debug -> Attach to process and select the IIS process in the Attach to Process dialog.
On IIS7, the name of the process is w3wp.exe, but you may need to select the Show processes from all users or Show process in all sessions before it becomes available.
When the debugger is properly attached to the IIS process, you can set one or more breakpoints in your code and invoke the service.
You must attach to the IIS process, namely aspnet_wp.exe under XP and w3wp.exe on 2003 server. This way you will hit breakpoints etc.
If you are looking for a way to test the WCF service itself, I would suggest using WcfTestClient.
And remember that the IIS process won't show in the task manager until you hit the server at least once (for example after a reboot, you'll have to hit a page on the server at least once to make the process start).
Thanks for the Solutions. I was getting the same problem.
My Solution is Working fine now with 2 svc files.
In Order to solve the problem i made two changes
In Web.Config I Commented the Line
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
and
Added Attribute [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] on the classs that are implementing the Interfaces.

Problem adding service reference to a WCF service hosted in a windows service

I am building a WCF service interface for an existing Windows service process. The purpose of the WCF interface is to provide an "Command Channel" to implement an administrative capability for the Windows Service. There are several OperationContract methods defined that are intended to extract information from and control the behaviour of the Windows service far beyond the Start/Stop/Pause capability of the Services applet.
This WCF service is intended to be part of the existing process. As such, running the WCF service in IIS or ServiceHost is not an option.
My problem is that although the ServiceHost does not throw an error on Open(), I cannot get "WCF Test Client" (or anyting else) to find the service.
This is my first WCF Service, and have had trouble finding examples or patterns that fit what I am trying to do. So I have no illusions and would not be suprised if I did many things wrong. Also, not that I have 'portSharingBinding=false'. I did have that on but it was throwing an error that pointed to another service that I do not wish to run.
Is port sharing required?
Config information:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="PortBinding" portSharingEnabled="false" />
</netTcpBinding>
</bindings>
<services>
<service name="NameChanged.ServiceManager.CommandService">
<endpoint address="net.tcp://localhost"
binding="netTcpBinding"
bindingConfiguration="PortBinding"
name="ServiceManagerCommandChannel"
contract="NameChanged.ServiceManager.ICommandService" />
</service>
</services>
</system.serviceModel>
I also tried the no config route using the following code:
ServiceHost host = new ServiceHost(typeof(CommandService)))
host.AddServiceEndpoint(typeof(ICommandService),
new NetTcpBinding(), "net.tcp://localhost:8000");
host.Open();
Also, no error on the Open(). But, no success connecting to the service.
Thanks for your time,
Jim
I can only speak to the WCF Test Client, but it is looking for the metadata for your service so it can generate a proxy for it. From the above configuration, it does not appear that you are exposing a metadata exchange endpoint. Take a look at this link for more info:
http://weblogs.asp.net/fabio/archive/2009/02/28/net-tcp-mex-endpoints-and-portsharing-in-wcf.aspx
You can access your service without using exposed metatdata to generate a proxy, but it will require you to manually create channels to do so:
http://msdn.microsoft.com/en-us/library/ms734681.aspx

WCF Security in a Windows Service

I have a WCF service which can run as Console App and a Windows Service. I have recently copied the console app up to a W2K3 server with the following security settings:
<wsHttpBinding>
<binding name="ServiceBinding_Security" transactionFlow="true" >
<security mode="TransportWithMessageCredential" >
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="Common.CustomUserNameValidator, Common" />
</serviceCredentials>
Security works fine with no problems. I have exactly the same code, but running in a windows service and I get the following error when I try to call any of the methods from a client:
System.ServiceModel.Security.MessageSecurityException was unhandled
Message="An unsecured or incorrectly secured fault was received from
the other party. See the inner FaultException for the fault code and detail."
Source="mscorlib"
StackTrace:
Server stack trace:
at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
......
(lots of stacktrace info - not very useful)
InnerException: System.ServiceModel.FaultException
Message="An error occurred when verifying security for the message."
The exception tells me nothing. I'm assuming that it has something to do with acces to system resources from the Windows Service. I've tried running it under the same account as the console app, but no luck. Does anyone have any ideas?
This is an error that sometimes has nothing to do with security.
I would recomend that you try first to get it to work without security, then just with message security, then with transport and finally with TransportWithMessageCredential.
Also if you are running the console app and the windows service app on the same machine make sure to stop the console app before starting the windows service, in order to avoid a port conflict
Enable diagnostics on the service. That should give you a pretty good idea of whether the service is even receiving the message and where the service is throwing an exception.
Update - I changed the customUserNamePasswordValidatorType from Custom to Windows. This worked fine in both the Console and Windows Service. I can only assume that something in the Custom Validator was causing the problem.
The custom validator used a custom config section in the App.config to validate the userid and Password. I would have thought this would have worked from a windows service though.
Thanks to all those who posted a reply.
You're using a custom user/name validator - does the Windows service have access to that file(s) ?
What account are you running the NT Service under ?
Does it work with all security turned off?? (just to see)
Marc