Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

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/" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top