Search code examples
.netwcfwcf-bindingwcf-endpointhostheaders

WCF is using the computer name instead of the IP address and cannot be resolved


I have a WCF service that works fine on the LAN but when trying to access it from outside the service reference fails.

My WCF service is hosted on a win2k3 box that is using a static IP no domain.


Solution

  • I found an answer to this after some digging - here is what I have found hopefully it can save someone else some time and bother.

    1.) Add the IP to the endpoint address & add a host name with the base IP address like so:

    <endpoint
      address="http://xx.xx.xx.xx/ServiceApp/Service.svc"
      binding="basicHttpBinding" contract="IService">
    </endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://xx.xx.xx.xx/ServiceApp/" />
      </baseAddresses>
    </host>
    

    This used to be enough to make my service reference work but the disco file started being returned with the computer name instead of the ip (I think this was after updating to .NET 4.0).

    2.) If you have a domain name (www.myDomain.com) then add this to the host header in IIS.

    3.) Add the IP address & computer name to the clients hosts file (easy fix not always possible to get all of your clients to add this to their host file however)

    4.) The BEST SOLUTION I found was to implement the ServiceHosts Factory Attribute as per "Timetheos" post here: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/c7fd51a2-773e-41d4-95a0-244e925597fe

    This worked well for me as I could test develop & debug my service library locally and then use a service app to deploy the service to my dev server and didn't have to change any configuration files after publishing it.

    This whole process was a total nightmare, and I wouldnt wish it upon anyone so if you are in the same situation and need anymore info on the above points just get in touch!