成功只从本地计算机连接我的WCF服务,除非指定了机器IP地址而不是localhost

时间:2013-10-22 17:28:51

标签: c# wcf

我有WCF service客户端连接到此服务并执行某些操作。 这是我的app.config文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="WCFServiceHostingInWinService.MySampleWCFService">
        <endpoint
          name="ServiceHttpEndPoint"
          address="" 
          binding="basicHttpBinding"
          contract="WCFServiceHostingInWinService.IMySampleWCFService">
        </endpoint>
        <endpoint
          name="ServiceMexEndPoint"
          address="mex"
          binding="mexHttpBinding"
          contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://192.168.0.192:8733/MySampleWCFService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

此服务安装在多台计算机上但在每台计算机上我需要将<add baseAddress="http://192.168.0.192:8733/MySampleWCFService/" />更改为相关IP address才能生效,指定localhost而不是Machine IP address我只能从本地机器连接到我的服务。

1 个答案:

答案 0 :(得分:0)

在基地址上使用0.0.0.0,它应该适用于系统上的每个网络接口,无论其地址如何。 localhost不起作用,因为它调用DNS查找,其值为127.0.0.1,仅为本地服务。