Home Articles

WCF发现查找 endpoints ,但地址是localhost

Viewed 766 times

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



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

  <compilation debug="true" />
 <!-- 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. -->
   <service name="NameService.GetNameService">
      <add baseAddress = "" />
    <!-- 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
      <dns value="localhost"/>
    <!-- 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"/>
     <!-- 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" />



svcutil.exe http://localhost: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 它没有在IIS中运行,它通过'正常的控制台应用程序托管

3 Answers

  • 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;
            new NetTcpBinding(SecurityMode.None),
            new UriBuilder { Scheme = Uri.UriSchemeNetTcp, Port = 8732, Host = "" , Path = "MyServiceContractPath" }.Uri

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

  • 1


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


    • 打开IIS

    • 右键单击您的网站,然后单击"properties"

    • 单击"Web Site"选项卡,然后单击"Web site identification" Headers 下的"Advanced"按钮

    • 您应该拥有该网站的默认标识(TCP端口8732) . 编辑它并确保主机标头值是您网站的域名(因此它应该说www.yourdomain.com)

    有关详细信息,请参阅http://forums.asp.net/p/1096811/1659596.aspx .