繁体   English   中英

客户端/服务器WCF聊天

[英]Client/Server WCF Chat

我在本地主机上托管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>

它给我那个错误

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

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

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

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

有关此绑定的更多信息,请参见WSDualHttpBinding类

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM