in WCF service can callback be made using wsHttpbinding? - wcf

I am new to WCF and windows services.
I have wcf service that is called from a class library. I am using that library in Windows service(WS) and this WS subscribes to the services and executes call back methods. The problem here is when I use
wsDualHttpBinding, I get an exception at the highlighted line
subscribe () {
InstanceContext ctx = new InstanceContext(this);
fcsc = new FeatureCreationServiceClient(ctx, "MyEndPoint"); //error
fcsc.Subscribe();
error says
Could not find endpoint element with name 'xx' and contract 'xx' in the ServiceModel client configuration section.
Some of our friends in StackOverFlow suggested replacing wsDualHttpBinding with WShttpBinding. Now the problem is gone but there is new exception saying
Contract requires Duplex, but Binding 'WSHttpBinding' doesn't support it or isn't configured properly to support it.
Please help me. I know that some one might have already asked this question but my search for that was in vain. Thanks in Advance.

Related

Proxy generated for WCF creating Message Contracts

I'm consuming a WCF service in my project for which I've added the reference using 'Add Service Reference...'. I expected it to generate a clean proxy with a ServiceClient entity and the Interface. Instead, I see that it has created a MethodNameRequest, MethodNameRequestBody, MethodNameResponse, MethodNameResponseBody entities for each OperationContract method.
So while invoking the service methods, the proxy passes to the service method an instance of MethodNameRequest with the input parameters of the method as the properties of the RequestBody. See below an example of a call to AboutInformationGet() method which doesn't accept any parameters.
public WCFDynamicInvocation.PostingService.AboutModel AboutInformationGet() {
WCFDynamicInvocation.PostingService.AboutInformationGetRequest inValue = new WCFDynamicInvocation.PostingService.AboutInformationGetRequest();
inValue.Body = new WCFDynamicInvocation.PostingService.AboutInformationGetRequestBody();
WCFDynamicInvocation.PostingService.AboutInformationGetResponse retVal = ((WCFDynamicInvocation.PostingService.IMIGQPosting)(this)).AboutInformationGet(inValue);
return retVal.Body.AboutInformationGetResult;
}
I believe this behavior is what one would expect to see in a Webservice Proxy. Hence I suspect that the WCF service is not properly configured.
Did someone here face this issue? What would be the change to be done at the service so that the proxy generated is similar to the WCF service.
Cheers.
There is a similar post here.
Right click your service reference -> Configure service reference... -> Check if "Always generate message contracts" check box is checked. Uncheck it and hit OK to regenerate the proxy to see if you get a normal proxy.
After struggling with this for some time, I've finally found that the cause for the message contracts in the proxy was the service interface had the following attribute:
[XmlSerializerFormat(Use = OperationFormatUse.Literal, Style = OperationFormatStyle.Document)]
As I understand, I could decorate the DataContracts with the following attribute to avoid wrapping
[MessageContract(IsWrapped = false)]
but the response still gets wrapped as the OperationContract hasn't been modified.
As there were no particular need to use XMLSerializer in place of WCF's default DataContractSerializer, we would remove the XmlSeralizerFormat decoration.

Enabling WCF Reading of an already existing MSMQ Queue

I have developed a WCF Self hosted service using .Net Framework 4.0.
[ServiceContract(SessionMode=SessionMode.Required)]
[ServiceKnownType(typeof(XmlDocument))]
public interface IMyMSMQ
{
[OperationContract(IsOneWay=true, Action="*")]
void OnMessageReceived(MsmqMessage<XmlDocument> msg);
}
My Class implementation of this interface looks like this.
public class MyMSMQ : IMyMSMQ, IErrorHandler
{
public void OnMessageReceived(MsmqMessage<XmlDocument> msg)
{
// Log Message To appropriate destination
Logger.LogMessage(msg);
}
}
I have tried multiple scenarios.
Scenario 1:
Launch service.
Launch Client app.
Send Message to queue using Client App
Notice that the Queue does not appear to get populated with the message because the service already read the message.
Notice that nothing else happens in the service.
Send one more message
Notice that message stays in the queue
Scenario # 2: This is similar to Scenario 1 but starting the apps were in different order
Launch Client app.
Send Message to queue using Client App
Notice that the Queue does appear to get populated with the message because the service is not started and has not read the message.
Launch service.
Notice that the message disappears.
Notice that nothing else happens in the service.
Send one more message
Notice that message stays in the queue
Every time the service starts, a message is removed from the queue so, it appears that my service IS in fact reading the message but it is not able to figure out where to send it or what to do with it once it reads the message.
I found out that the code in the WCF Library was not the problem. It was how I was defining the endpoint binding.
MsmqIntegrationBinding binding = new MsmqIntegrationBinding(MsmqIntegrationSecurityMode.None);
binding.ReceiveTimeout = new TimeSpan(0, 1, 0); // set timeout to 1 minute.
binding.ReceiveErrorHandling = ReceiveErrorHandling.Fault;
this.AddServiceEndpoint(typeof(eRxMsmqWCF.IeRxMSMQ), binding, GetMQUri());
It needed to have the MsmqIntegrationBinding (which requires you to include the following using statement: using System.ServiceModel.MsmqIntegration;.
Sometimes I rely on intellisense too much. The MsmqIntegrationBinding is not present under the standard System.ServiceModel where the other bindings are located. So I used the NetMsmqBinding instead.

How to handle WCF Service efficiently with error handling

I keep getting this error after I throw an error in WCF Service:
The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state.
The error is thrown by service using
throw new FaultException<DatabaseFault>(new DatabaseFault(e.Message));
How can I handle this, in a way that doesn't need to restart both the client and the service each time?
I'm using WCF 4.0, C#.
Edit 1: I use net.tcp binding for the WCF service.
Edit 2: I want an efficient way to work with WCF. It is not related to what John S says.
Edit 3: My code works. But I think it's not running like it should(the way it was designed).
This is the console application which hosts my service :
using (ServiceHost host = new ServiceHost(typeof(AuctionService)))
{
Console.WriteLine("AuctionWCF.TestHost Started");
host.AddServiceEndpoint(
typeof(IAuctionService),
new NetTcpBinding(),
"net.tcp://localhost:9000/AuctionWcfEndPoint");
host.Open();
Console.WriteLine("AuctionWCF.TestHost listens for requests");
Console.ReadLine();
}
This is the client:
AuctionService = new ChannelFactory<IAuctionService>(
new NetTcpBinding(),
new EndpointAddress("net.tcp://localhost:9000/AuctionWcfEndPoint")).CreateChannel();
Am I doing something wrong?
Do you use a ChannelFactory? If so, this answer shows an example of a ChannelFactoryManager that has worked pretty good for me.
This is a pretty good approach and this is what I wanted to discover:
http://blog.tallan.com/2009/05/06/recover-from-a-wcf-service-fault-part-2-generic-serviceclientfactory-class/
I took some of the good parts from diggingforfire answer too.
Found anothe good answer that could be used as Best Practice here

Error WSE012 (Action Missing) when consuming WSE webservice

For a small project I need to use (consume) an external (secure) webservice.
This webservice uses SOAP1.2 protocol with WSE extention (username + password)
I use VB (VS2008) and added the Service Reference, customized the app.config to use wsHttpBinding rather than basicHttpBinding
One of the public Functions of the webservice is called
searchByName(String, String)As System.Xml.XmlElement
In code I first initialize the security;
wsTST.ClientCredentials.UserName.UserName = "mycompanyname"
wsTST.ClientCredentials.UserName.Password = "abc%2011!"
and then call the Function (the code fails here):
Debug.WriteLine(wsTST.searchByName("John", "Johnson"))
A first chance exception of type 'System.ServiceModel.FaultException' occurred in mscorlib.dll.
Error message:
WSE012: The input was not a valid SOAP message because the following information is missing: action.
Can anyone tell me if consuming a WSE webservice is possible from VB.NET2008?
And can anyone point me in the right direction?
I have searched for hours, but could not find any relevant information.
Regards, Frank

How can I check connection is still valid for Silverlight client using net.tcp for duplex?

I'm putting together a WCF service using net.tcp and netTcpBinding to get duplex comms with my Silverlight client. I call into the service from the Silverlight app and the service calls out to another server, passing it a callback method in the WCF service class. The remote server calls back several times and each time it does, the WCF service uses the callbackchannel to send the data to the Silverlight client. It all works nicely most of the time.
If the user puts in a big request, I get a TimeoutException after a large number of callbacks have already worked. (Clearly, there's some work to do elsewhere to prevent this but I'd like to robustify the service, first.)
I was expecting to do some kind of 'if (client.ConnectionState == faulted)' check before trying to call back to the Silverlight client but I can't seem to find the object that holds the state of the connection. Is there one? Am I approaching this from the wrong side?
This is my first venture into a service net.tcp and duplex. I just moved house and my WCF bible is still in a box. Somewhere. :-) So, I can't do my usual background reading.
Any pointers would be gratefully received. Here's some bare code in case my description is too soupy:
private IActiveDirectoryClient client;
private AsyncSearchRunner runner;
public void Search(Request request)
{
this.client = OperationContext.Current.GetCallbackChannel<IActiveDirectoryClient>();
runner = new AsyncSearchRunner();
runner.Run(request.SearchRoot, request.SearchFilter, request.PageSize,
System.DirectoryServices.Protocols.SearchScope.Subtree, SendObjects);
}
private void SendObjects(List<DirectoryObject> items)
{
Response response = new Response();
response.DirectoryObjects = items.ToArray();
client.SendResponse(response);
}
Yes, there is a State property that is defined in the ClientBase<> class (all the proxy classes are derived from ClientBase<>).
There are some proxy wrappers out there that handle fault states of the connection and re-establish connections as needed. Google for "wcf proxy wrapper".
You can also home-brew something if you use some kind of ServiceLocator pattern.