1

我尝试使用 WSDualHttpBinding 实现 WCF 回调。该服务托管在 IIS 7 上。

当我在与主机相同的机器上为服务创建示例客户端时,它工作正常。但是当我从网络上的不同系统运行同一个客户端时,我得到了超时异常

服务器堆栈跟踪:在 System.ServiceModel.Channels.ReliableRequestor.ThrowTimeoutException() 在 System.ServiceModel.Channels.ReliableRequestor.Request(TimeSpan timeout) 在 System.ServiceModel.Channels.ClientReliableSession.Open(TimeSpan timeout) 在 System.ServiceModel.Channels .ClientReliableDuplexSessionChannel.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)在 System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel 通道,TimeSpan 超时)在 System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan 超时,CallOnceManager 级联)在系统.ServiceModel.Channels。System.ServiceModel.Channels.ServiceChannel.Call 中的 ServiceChannel.EnsureOpened(TimeSpan 超时)(字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出,TimeSpan 超时)在 System.ServiceModel.Channels.ServiceChannel.Call (字符串操作,布尔单向,ProxyOperationRuntime 操作,Object[] 输入,Object[] 输出)在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage 方法调用,ProxyOperationRuntime 操作)在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 的 ProxyOperationRuntime 操作,Object[] ins,Object[] outs)System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 的 ProxyOperationRuntime 操作,Object[] ins,Object[] outs)

CallbackContract 如下所示:

 public interface IMyServiceCallBack
    {
        [OperationContract(IsOneWay = true)]
        void Notify();
}

我也指定了

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession,ConcurrencyMode = ConcurrencyMode.Reentrant)]

Client上的app.config如下:

 <wsDualHttpBinding>
            <binding name="WSDualHttpBinding_Callback" closeTimeout="00:01:00"                         clientBaseAddress="http://10.1.3.199:8002/myServiceHost/myService.svc/Endpoint"
                     openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                     bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                     maxBufferPoolSize="97108864" maxReceivedMessageSize="97108864"
                     messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="97108864" maxArrayLength="97108864"
                  maxBytesPerRead="97108864" maxNameTableCharCount="97108864" />              
              <security mode="None"/>
            </binding>
          </wsDualHttpBinding>
<client>
 <endpoint address="http://10.1.3.199/myServiceHost/myService.svc/Endpoint"
                binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_Callback"
                contract="myService.ServiceContract" name="WSDualHttpBinding_Callback" />
</client>

我错过了什么!!!

4

1 回答 1

2

WSDualHttpBinding仅当服务器和客户端都可以访问端口 80 时才有效。是的,这意味着服务器将尝试打开与客户端的 TCP 连接。通过互联网WSDualHttpBinding基本上是无用的,因为大多数用户坐在路由器后面,这些路由器不会将连接从服务器路由回客户端。

如果您在同一个网络上(如您所说),那么您需要确保客户端计算机上的防火墙允许端口 80(或您使用的任何端口)。

另一种方法是使用NetTcpBinding它打开一个允许双工通信的单个传出tcp 连接。如果您的客户端和服务器始终在同一个网络上,这是一个很好的选择。

有关 WSDualHttpBinding 的更多信息,请参阅此帖子

于 2012-08-07T11:05:53.867 回答