0
我在WCF回调机制方面遇到了一些麻烦。他们有时会工作,但大多数时候他们不工作。WCF回调经常中断
我对回调一个非常简单的接口来实现:
public interface IClientCallback {
[OperationContract]
void Log(string content);
}
然后我implmenent与客户端上的类接口:
[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!”);
但它只是挂在那里,过了一段时间客户抱怨超时。有一个简单的解决方案,为什么?
也许我应该提到我继承了代码,而且都是C#专家。你能告诉我在哪里可以找到那些特定的信息吗? – cdecker 2010-05-22 02:20:38