WCF CallBack在同一台机器上运行,但不能在网络上运行

时间:2012-08-07 09:31:44

标签: wcf callback

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

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

服务器堆栈跟踪:System.ServiceModel.Channels.ReliableRequestor.ThrowTimeoutException()处于System.ServiceModel.Channels.ReliableRequestor.Request(TimeSpan超时),位于System的System.ServiceModel.Channels.ClientReliableSession.Open(TimeSpan超时)。 Service.ServiceModel.Channels.OnOpen(TimeSpan超时),位于System.ServiceModel.Channels.OmunOpen(TimeSpan超时)的System.ServiceModel.Channel.OnOpen(TimeSpan超时),System.ServiceModel.Channels.OmunOpen(TimeSpan超时),位于System.ServiceModel.Channels.CommunicationObject.Open( TimeSpan超时)System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel频道,TimeSpan超时)在System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan超时,CallOnceManager级联) )System.ServiceModel.Channels.EnsureOpened(TimeSpan timeout)at System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOpera) System.ServiceModel上的System.ServiceModel.Channels.ServiceChannel.Call(String action,Boolean oneway,ProxyOperationRuntime operation,Object [] ins,Object [] outs)中的tionRuntime操作,Object [] ins,Object [] outs,TimeSpan timeout System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)中的.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)

CallbackContract看起来如下:

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

我也指定了

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

客户端上的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>

我失踪了什么!

1 个答案:

答案 0 :(得分:2)

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

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

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

有关WSDualHttpBinding

的更多信息,请参阅this帖子