WCF回调通常会中断

时间:2010-05-22 00:30:52

标签: c# wcf timeout callback

我在使用WCF回调机制时遇到了一些麻烦。他们有时会工作,但大多数时候他们没有。

我有一个非常简单的接口来实现回调:

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

然后,我在客户端上使用类来实现该接口:

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

在客户端我最终连接到服务器:

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());
}

要调用回调,我使用以下内容:

OperationContext.Current.GetCallbackChannel()。Log(“Hello World!”);

但它只是挂在那里,过了一会儿客户抱怨超时。有一个简单的解决方案,为什么?

1 个答案:

答案 0 :(得分:1)

听起来像是.ClientConfig的问题,你能在这里发帖吗?