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

丶灬走出姿态 提交于 2019-11-27 04:31:26

问题


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.


回答1:


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.




回答2:


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.




回答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!




回答4:


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" />



回答5:


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>


来源:https://stackoverflow.com/questions/6863464/wcf-is-using-the-computer-name-instead-of-the-ip-address-and-cannot-be-resolved

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!