WCF Callbacks often break

Posted by cdecker on Stack Overflow See other posts from Stack Overflow or by cdecker
Published on 2010-05-22T00:30:52Z Indexed on 2010/05/22 1:20 UTC
Read the original article Hit count: 386

Filed under:
|
|
|

I'm having quite some trouble with the WCF Callback mechanism. They sometimes work but most of the time they don't.

I have a really simple Interface for the callbacks to implement:

public interface IClientCallback {
  [OperationContract]
  void Log(string content);
}

I then implmenent that interface with a class on the client:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] [ServiceContract]
internal sealed class ClientCallback : IClientCallback {
  public void Log(String content){
    Console.Write(content);
  }
}

And on the client I finally connect to the server:

NetTcpBinding tcpbinding = new NetTcpBinding(SecurityMode.Transport);
EndpointAddress endpoint = new EndpointAddress("net.tcp://127.0.0.1:1337");
ClientCallback callback= new ClientCallback();
DuplexChannelFactory<IServer> factory = new DuplexChannelFactory<IServer>(callback,tcpbinding, endpoint);
factory.Open();
_connection = factory.CreateChannel();
((ICommunicationObject)_connection).Faulted += new EventHandler(RecreateChannel);
try {
  ((ICommunicationObject)_connection).Open();
} catch (CommunicationException ce) {
  Console.Write(ce.ToString());
}

To invoke the callback I use the following:

OperationContext.Current.GetCallbackChannel().Log("Hello World!");

But it just hangs there, and after a while the client complains about timeouts. Is there a simple solution as to why?

© Stack Overflow or respective owner

Related posts about c#

Related posts about wcf