WCF发现查找端点,但地址是localhost

时间:2010-09-17 03:26:56

标签: c# network-programming wcf service-discovery

我有一个名为“GetNameService”的wcf可发现服务,该服务托管在PC @ 10.0.0.5:8732上。它由wsHttpBinding托管,可通过'UdpEndpoint发现。我还有一个客户端@ 10.0.0.9,可以在同一个网络中发现这些服务。当我运行客户端时,我能够发现服务,但发现的服务的终点是其中有localhost。怎么会发生这种情况,请帮我解决这个问题。

更多信息,

使用了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="NameService.GetNameService">
    <host>
     <baseAddresses>
      <add baseAddress = "http://10.0.0.5:8732/Design_Time_Addresses/NameService/GetNameService/" />
     </baseAddresses>
    </host>
    <!-- Service Endpoints -->
    <!-- Unless fully qualified, address is relative to base address supplied above -->
    <endpoint address ="" binding="wsHttpBinding" contract="NameService.IGetNameService">
     <!--
       Upon deployment, the following identity element should be removed or replaced to reflect the
       identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
       automatically.
     -->
     <identity>
      <dns value="localhost"/>
     </identity>
    </endpoint>
    <!-- Metadata Endpoints -->
    <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
    <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
   </service>
  </services>
  <behaviors>
   <serviceBehaviors>
    <behavior>
     <!-- To avoid disclosing metadata information,
     set the value below to false and remove the metadata endpoint above 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="False" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
 </system.serviceModel>

</configuration>

我打开了客户端计算机中的浏览器并输入了服务地址,我看到了服务详细信息页面,但仍然是wsdl链接指向localhost(如下所示)

svcutil.exe http://localhost:8732/Design_Time_Addresses/NameService/GetNameService/?wsdl

而不是

svcutil.exe http://10.0.0.5:8732/Design_Time_Addresses/NameService/GetNameService/?wsdl

此外,相同的应用程序似乎在我的工作场所工作,其中有一个可用的DNS和系统连接通过'一个开关,在那里因为它不能在我的家里工作的电脑通过'路由器连接。这会影响某些事情吗?!

更新 它没有在IIS中运行,它通过“普通的控制台应用程序

进行托管

3 个答案:

答案 0 :(得分:1)

如果您在IIS上运行,则必须为您的站点设置默认主机名规则:

  1. 打开IIS
  2. 右键点击您的网站,然后点击“属性”
  3. 点击“网站”标签,然后点击“网站标识”标题下的“高级”按钮
  4. 您应该拥有该网站的默认身份(TCP端口8732)。编辑并确保主机标头值是您网站的域名(因此应该说www.yourdomain.com)
  5. 有关详情,请参阅http://forums.asp.net/p/1096811/1659596.aspx

答案 1 :(得分:1)

使用。

解决代码(对于tcp.net连接)
// Add discovery feature.
m_Host.AddServiceEndpoint(new Discovery.UdpDiscoveryEndpoint());
m_Host.Description.Behaviors.Add(new Discovery.ServiceDiscoveryBehavior());
// Add ordinary service feature
var binding = new NetTcpBinding();
binding.Security.Message.ClientCredentialType = MessageCredentialType.None;
binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
m_Host.AddServiceEndpoint(
        typeof(IMyServiceContract),
        new NetTcpBinding(SecurityMode.None),
        new UriBuilder { Scheme = Uri.UriSchemeNetTcp, Port = 8732, Host = "10.0.0.5" , Path = "MyServiceContractPath" }.Uri
        );

剩下的唯一(可能更小)问题是将哪台计算机IP设置为主机...输入的Uri是在DiscoveryClient.Find(...)响应中返回的。

答案 2 :(得分:0)

如果你仍然需要这个,事实证明,你可以在baseAddress中使用通配符:

<add baseAddress = "http://*:8732/Design_Time_Addresses/NameService/GetNameService/" />