1

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!

Martin Brown
  • 24,692
  • 14
  • 77
  • 122
Attila Klenik
  • 753
  • 6
  • 13
  • 1
    Should you add host entry for server where service is hosted in host file of your client machine. – Pankaj Kapare Jan 19 '15 at 00:20
  • Simple, and works, but it kind of destroys the purpose of discovery. Plus I plan to launch multiple VMs with the same service. I guess I could map every VM in the network to its IP in the client's hosts file (should work because of static IPs, and small network), but it's more of a workaround than a solution to the problem. Please post your comment as an answer and if no one comes up with a more general solution in 2-3 days, I'll accept your answer as the solution. – Attila Klenik Jan 19 '15 at 01:23
  • If your VMs where you are planning to host this service and clients are part of same network domain then you don't need this workaround. It will work without any changes in host file. If this isn't scenario then you need to host service on public static IP and no matter where your clients resides (in or out of network of your server) they should be able to access service. – Pankaj Kapare Jan 19 '15 at 01:52
  • I set up two VMs on the same VMware network. One for a simple client console app that does the discovery as illustrated above, and one that hosts the service. Same error. Both VMs have only one network interface (to the 192.168.221.x network). But editing the hosts file looks like a proper workaround for the moment. – Attila Klenik Jan 19 '15 at 20:22

0 Answers0