【问题标题】:Client/Server WCF Chat客户端/服务器 WCF 聊天
【发布时间】:2013-09-14 18:06:48
【问题描述】:

我在本地主机上托管 WCF 服务,并且客户端在同一主机上运行,​​它在同一台机器上运行时运行良好,但是当我在另一台机器上安装客户端并尝试连接到服务器时它失败...这是服务器的配置文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="wsDualBinding">
          <security mode="None" />
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Metadata">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="Metadata" name="ChatService.ChatManager">
        <endpoint address="duplex" binding="wsDualHttpBinding" bindingConfiguration="wsDualBinding"
          contract="ChatService.IChat" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:2525/chat/" />
            <!--<add baseAddress="net.tcp://localhost:1717/chat/" />-->
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
</configuration>

客户端配置

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <wsDualHttpBinding>
        <binding name="NewBinding0">
          <security mode="None" />
        </binding>
      </wsDualHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://192.168.1.10:2525/chat/duplex" binding="wsDualHttpBinding"
        bindingConfiguration="NewBinding0" contract="ChatService.IChat" name="mgr" />
    </client>
  </system.serviceModel>
</configuration>

它给了我这个错误

套接字连接被中止。这可能是由于处理您的消息时出错或远程主机超出接收超时时间,或底层网络资源问题引起的

【问题讨论】:

  • 请同时发布客户端机器的配置。另外,失败时收到的错误信息是什么?
  • 如果您在另一台机器上使用此客户端配置,则问题出在您的客户端端点 - 您仍在引用 localhost,因此客户端将在同一台机器上查找服务.
  • 对不起,我知道,这是一个旧配置,我会改变它
  • 所以这不是 localhost 的地址问题。防火墙是否阻塞了 2525 端口?
  • 另外,我在您的客户端 (NewBinding0) 的绑定定义中看不到 clientBaseAddress 属性。

标签: c# asp.net wcf


【解决方案1】:

wsDualHttpBinding 要求客户端建立一个服务可以连接的地址,以便提供回调。这是在绑定元素的配置文件中完成的,如下所示:

<wsDualHttpBinding name="NewBinding0"
                   clientBaseAddress="http://machine_name:port/Client/">

由于客户端与服务位于不同的计算机上,因此您需要指定客户端的计算机名称。

有关此绑定的更多信息,请参阅WSDualHttpBinding Class

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-04
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    • 2016-04-09
    • 2015-10-12
    相关资源
    最近更新 更多