How to associate a WCF service with an IP address

I am developing a WCF service hosted by IIS using VSTS2008 + C # + .Net 3.5. I find that when accessing a service with a client using the Add Service Reference ... the client should be able to resolve the computer name by IP address, because the WSDL refers to some schema file by machine name. Here is an example of a part of the WSDL file, in order to parse the WSDL file from the client side to create a proxy server, we should be able to resolve the testmachine1 machine name for the corresponding IP address,

<xsd:import schemaLocation="http://testmachine1/service.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/> 

My question is, for some reason, the machine name cannot be resolved all the time (for non-technical reasons), so I want to bind to the IP address of the IIS server hosting. Is it possible? If so, appreciate if anyone can advise. Here is my current WCF web.config file, I want to know how to change it so that it works with the IP address,

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service behaviorConfiguration="Foo.WCF.ServiceBehavior" name="Foo.WCF.CustomerManagement"> <endpoint address="" binding="basicHttpBinding" contract="Foo.WCF.ICustomerManagement"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <serviceBehaviors> <behavior name="Foo.WCF.ServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> 

thanks in advance George

+1
source share
2 answers

If your WCF service is hosted in IIS, you cannot set a separate address. You must use the URL of the virtual directory in which your SVC file lives, either with the name of the machine ( http: //yourserver/virtualdir/myservice.svc ) or IP ( http://123.123.123.123/virtualdir/myservice.svc ) .

If you use IP to add a service reference, this IP address will be used in the WSDL generated by the service import.

If you host the WCF service yourself (Windows service, console application), you can set the service address in config and use the machine name or IP address.

Mark

+2
source

I had the same problem and I saw your post looking for answers to my own problem.

I think I might have found a solution that was supposed to change the binding of the IIS site to the IP address. I still don't understand why this cannot be a parameter in the .config file.

Here is a link to the solution found ( http://blogs.msdn.com/wenlong/archive/2007/08/02/how-to-change-hostname-in-wsdl-of-an-iis-hosted-service.aspx ) .

Here is a link to my post on my issue ( WCF .NET service links use the server name, not the IP address causing the problems when using ).

Here is a link to my post about finding a solution ( WCF (hosting service in IIS) - the name of the machine that is automatically selected by WCF, not IP? ).

+1
source

All Articles