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