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

发布于 2024-09-23 23:54:03 字数 3235 浏览 3 评论 0 原文

我有一个名为“GetNameService”的 wcf 可发现服务,该服务托管在 PC @ 10.0.0.5:8732 上。它由 wsHttpBinding 托管,并可通过 UdpEndpoint 发现。我还有一个客户端@ 10.0.0.9,它在同一网络中发现此类服务。当我运行客户端时,我能够发现该服务,但发现的服务的终点是本地主机。怎么会出现这种情况,请大家帮帮我。

更多信息,

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< /a>

此外,同一个应用程序似乎可以在我的工作场所工作,那里有可用的 dns,并且系统通过交换机连接,但它在我的家里不起作用,那里的电脑通过路由器连接。这会影响什么吗?!?

更新 它不在 IIS 中运行,而是通过普通控制台应用程序托管

I have a wcf discoverable service called "GetNameService" which is hosted on a PC @ 10.0.0.5:8732. It is hosted with wsHttpBinding and is discoverable thru' UdpEndpoint. I also have a client @ 10.0.0.9 which discovers for such services in the same network. When I ran the client, I am able to discover the service but the end point of the service discovered is having localhost in it. How can this happen, please help me out in this.

Some more information,

App.config used

<?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>

I opened up the browser in the client machine and typed the service address, I get to see the service details page but still the wsdl link points to localhost (shown below)

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

instead of

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

Also, the same application seems to work in my work place where there is a dns available and the systems are connect thru' a switch, where as it doesn't work at my home where the pcs are connect thru' a router. Could this influence something ?!?

Update
It is not running in IIS, it is hosted thru' a normal console application

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

中二柚 2024-09-30 23:54:04

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

  1. 打开 IIS
  2. 右键单击​​您的网站,然后单击“属性”
  3. 单击“网站”选项卡,然后单击“Web 站点”下的“高级”按钮站点标识”标题
  4. 您应该拥有网站的默认身份(TCP 端口 8732)。编辑该内容并确保主机标头值是您网站的域名(因此应该显示 www.yourdomain.com)

请参阅 http://forums.asp.net/p/1096811/1659596.aspx 了解更多详细信息。

If you are running on IIS, you have to have a default hostname rule for your site:

  1. Open IIS
  2. Right click on your website and click "properties"
  3. Click the "Web Site" tab and then click the "Advanced" button under the "Web site identification" heading
  4. You should have a default Identity for the website (TCP port 8732). Edit that and make sure the host header value is the domain name for your website (so it should say www.yourdomain.com)

See http://forums.asp.net/p/1096811/1659596.aspx from more details.

静谧幽蓝 2024-09-30 23:54:04

通过使用在代码中解决了这个问题(对于 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(...) 响应中返回的 Uri。

Solved it in code (for a tcp.net connection) by using.

// 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
        );

The only (perhaps smaller) problem that remains is which of the computers IP to set as host... The Uri entered is the one that is returned in the DiscoveryClient.Find(...) response.

稀香 2024-09-30 23:54:04

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

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

In case you still need this, it turns out, you can just use a wildcard in baseAddress:

<add baseAddress = "http://*:8732/Design_Time_Addresses/NameService/GetNameService/" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文