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

5

9

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.

Karelian answered 28/7, 2011 at 17:56 Comment(2)
If it works locally and the wsdl shows up on the port 80 web page, is it possible your service is using other ports and the router firewall is blocking outside access to those ports?Caporal
Firewall is no problem, the computer name could not be resolved outwith the LAN but I have a solution now. Thnx anyway.Karelian
K
3

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!

Karelian answered 2/8, 2011 at 11:25 Comment(1)
Hi baileyswalk, when I change it to ip address, it ask me username and password , and when I provide that it doesn't connectOlav
L
16

This is what worked for me. In config file

< serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
< / system.serviceModel >

If it is set to false, I was getting that crazy computername substitution.

multipleSiteBindingsEnabled="true" seems to be all that I have to do for this to work as it should.

Logicize answered 26/1, 2012 at 0:24 Comment(1)
Thank you, it's appropriate solution for this issueFrederique
K
5

I was looking into an approach to reuse the Host header from HTTP request. In my opinion this should work in development as in production.

It turns out is as easy as:

<behaviors>
    <serviceBehaviors>
       <behavior name="...">
         ...
         <useRequestHeadersForMetadataAddress />
       </behavior>
    </serviceBehaviors>
</behaviors>

This way if the WSDL endpoint is accessible by a client this ensures that all the associated wsdl/xsd resources will be accessible with the same base url.

Katinka answered 11/11, 2013 at 5:52 Comment(0)
K
3

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!

Karelian answered 2/8, 2011 at 11:25 Comment(1)
Hi baileyswalk, when I change it to ip address, it ask me username and password , and when I provide that it doesn't connectOlav
C
2

You can use an asterisk * (wildcard) in the place of LocalHost or machine name in the base url like so:

<add baseAddress="net.tcp://*:4502/WxWcfService_01" />
Cologne answered 10/10, 2014 at 21:23 Comment(0)
A
0

Set service end point and httpgeturl like this.

<services>
    <service behaviorConfiguration="serviceBehaviour" name="Demo.Service.MultiEndPointsService">
        <endpoint address="http://192.168.1.2/Demo.Service/MultiEndPointsService.svc/basic" binding="basicHttpBinding" bindingConfiguration="basicBinding"      contract="Demo.Service.MultiEndPointsService" />
    </service>
</services>
<behaviors>
    <serviceBehaviors>
        <behavior name="serviceBehaviour">
            <serviceMetadata httpGetEnabled="true" httpGetUrl="http://192.168.1.2/Demo.Service/MultiEndPointsService.svc/basic"/>     
            <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
    </serviceBehaviors>
</behaviors>
Atkins answered 22/10, 2013 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.