發送到 net.tcp://192.168.1.18:8732/CallbackService 的請求操作在配置的超時(00:00:59.9879994)內未收到回復。
分配給此操作的時間可能已經是更長超時的一部分。這可能由於服務仍在處理操作或服務無法發送回復消息。
請考慮增加操作超時(將通道/代理轉換為 IContextChannel 並設置 OperationTimeout 屬性)並確保服務能夠連接到客戶端。
網上找了很多資料,都無法解決我的問題。
INotificationServices proxy; DuplexChannelFactory<INotificationServices> channelFactory; const string wsDualHttpBinding = "WSDualHttpBinding_INotificationServices"; const string netTcpBinding = "NetTcpBinding_INotificationServices"; InstanceContext context = new InstanceContext(new NotificationServiceCallBack()); channelFactory = new DuplexChannelFactory<INotificationServices>(context, wsDualHttpBinding); proxy = channelFactory.CreateChannel(); proxy.SendNotification("Are u ready?"); channelFactory = new DuplexChannelFactory<INotificationServices>(context, netTcpBinding); proxy = channelFactory.CreateChannel(); proxy.SendNotification("Are u ready?"); Console.WriteLine("Press Enter to terminate the client"); Console.ReadLine();
客戶端配置
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <client> <endpoint address="http://192.168.1.18:8888/CallbackService" binding="wsDualHttpBinding" bindingConfiguration="" contract="Library.INotificationServices" name="WSDualHttpBinding_INotificationServices" /> <endpoint address="net.Tcp://192.168.1.18:8732/CallbackService" binding="netTcpBinding" bindingConfiguration="" contract="Library.INotificationServices" name="NetTcpBinding_INotificationServices" /> </client> </system.serviceModel> </configuration>
問題在於
context = new InstanceContext(new NotificationServiceCallBack());
這個是無法共用的。
第二個代理必須重新new一個新的InstanceContext對象,才能夠正常查詢