【问题标题】:WCF CallBack works on same machine, but does not work over networkWCF CallBack 在同一台机器上工作,但不能通过网络工作
【发布时间】:2012-08-07 09:31:43
【问题描述】:

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

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

服务器堆栈跟踪:在 System.ServiceModel.Channels.ReliableRequestor.Request(TimeSpan timeout) 在 System.ServiceModel.Channels.ClientReliableSession.Open(TimeSpan timeout) 在 System.ServiceModel.Channels.ReliableRequestor.ThrowTimeoutException()。 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 超时)在 System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel 通道,TimeSpan 超时)在 System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan 超时,CallOnceManager 级联)在 System.ServiceModel.Channels.ServiceChannel.EnsureOpened(时间跨度超时)在 System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOpera System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel .Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

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>

我错过了什么!!!

【问题讨论】:

    标签: wcf callback


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 我真的很想让 wsDualHttpBinding 工作。防火墙已关闭。我不认为这是防火墙问题。我还应该看哪些其他东西?
    • 不确定,您可能需要使用wireshark 来查看发生了什么。另外,客户端是否能够访问服务器? (即在服务器上放一条日志语句,看看这种方式是否有效)
    猜你喜欢
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多