Attila Klenik
Attila Klenik

Reputation: 763

WCF Discovery returns machine names in metadata (cannot be resolved)

So I have a WCF service hosted in IIS8 (Windows Server 2012). Here's the relevant part of the configuration file:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <services>
      <service name="MovieCorner.DAL.Service.MovieCornerDalService">
        <host>
          <baseAddresses>
            <add baseAddress="http://192.168.221.101/MovieCorner/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <endpoint address="" binding="basicHttpBinding" 
           contract="MovieCorner.Commons.Services.IMovieCornerDalService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint kind="udpDiscoveryEndpoint" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="True" />
          <serviceDiscovery />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

A simple service with a simple binding, and with a discovery endpoint. The service is up and running, everything works fine. Almost...

Here's the code I'm using on the client side (it's just a "unit" test):

var client = new DiscoveryClient(new UdpDiscoveryEndpoint());
var response = client.Find(new FindCriteria(typeof(IMovieCornerDalService)));

Assert.IsNotNull(response);
Assert.IsNotNull(response.Endpoints);
Assert.IsTrue(response.Endpoints.Count > 0);

foreach (var endpoint in response.Endpoints)
{
    Console.WriteLine("Address: {0}; Contract: {1}", endpoint.Address, endpoint.ContractTypeNames[0]);
}

The code successfully finds the only running service. The output is the following:

Address: http://ws12-iis8/MovieCorner/MovieCornerDalService.svc; Contract: http://tempuri.org/:IMovieCornerDalService

The address is returned with the machine name that hosts the service. After the discovery I want to use the service like this:

var endpoint = response.Endpoints[0];
var clientProxy = ChannelFactory<IMovieCornerDalService>.CreateChannel(new BasicHttpBinding(), endpoint.Address);
var user = clientProxy.RegisterUser("1234"); // problem

The actual method call throws an exception, and the inner exception is the following: System.Net.WebException: The remote name could not be resolved: 'ws12-iis8'

The "unit" test runs in my PC, the service is hosted in a VM. I can reach the service at the http://192.168.221.101/MovieCorner/MovieCornerDalService.svc address. But not with the machine name address.

What am I missing? What are my options? How can I retrieve the actual (private) IP of the service hosting VM? I searched for different metadata options, but I'm not a pro in the web world, so I don't know what I'm looking for.

If you need more information, let me know. Thanks for your time!

Upvotes: 1

Views: 122

Answers (0)

Related Questions