Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET WCF service references use server name rather than IP address causing issues when consuming

Tags:

.net

iis

wcf

So, I'm a newbie to WCF...

I created my ServiceLibrary and web-site project that consumed the ServiceLibrary. I am able to access the service by creating a proxy class from the WSDL that was generated using svcutil.exe and then used this class to access the methods in my service. All of this was fine on my local machine.

I then moved the service to my test development server (not on the domain, so I am accessing via an IP address) and added the site to IIS. I was able to access the service via //ip/ServiceSite/Service.svc and the WSDL via //ip/ServiceSite/Service.svc?wsdl.

However, when trying to consume this service I received an error about references being incorrect. When I look at the //ip/ServiceSite/Service.svc the link that is provided to generate the proxy class contains the machine name of the server in the address and when I look at the WSDL the references to the schemas also contain the machine name in the URL. This machine name cannot be accessed over the network as it is not on the domain.

Is there a way that instead of the machine name for the server being placed in those references that it would use the IP address? Or are there any other solutions to be able to access the service by IP address?

like image 619
dwhittenburg Avatar asked Dec 13 '22 00:12

dwhittenburg


2 Answers

Put

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

befor closing the system.serviceModel tag. It should end like this:

<system.serviceModel > 
       .
       .
       .
   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel >
like image 121
user1967079 Avatar answered Dec 30 '22 09:12

user1967079


Take a look at the WCFExtras library. In particular, the section on "Override SOAP Address Location URL". The brief answer is that you need a custom endpoint behavior provided by implementing IWsdlExportExtension.ExportEndpoint.

like image 45
Craig Avatar answered Dec 30 '22 10:12

Craig