Problem description
I encountered an issue where adding a service reference failed after I deployed a normal service to the server locally.
The problem was resolved after replacing localhost with the base address in the configuration file with the server's IP address.
But I feel that this is not a problem because of careless writing the wrong address, the real reason may not be so simple.
Analysis
You need to fill in the service's metadata address when adding a service reference, then click the Go button.
It could have been this way when it went wrong:
It could be like this:
Let's look at why they failed.
Open the corresponding address in the browser to see:
And also
Some of the links on the page are based on localhost, which is the base address set in the configuration file.
The preceding error hints are also mainly focused on the inability to get data on localhost, which is supposedly obtained from the server.
This is the reason for the problem-the metadata generated automatically by Http-get uses the base address of the service in the configuration.
So when I replace localhost with the base address in the configuration file with the server's IP address, the problem is resolved.
Solution Solutions
Although the method of using IP directly in the base address is valid, it is awkward, right.
Because we may access the service through many ways, such as IP, hostname, domain name, and the service may be deployed on a host in the intranet.
What should we do with so many complicated situations?
In fact WCF has been ready for us, just open the <useRequestHeadersForMetadataAddress> switch in the configuration, to:
Enables the retrieval of metadata address information from the request message headers.
1 <Behaviors>2 <servicebehaviors>3 <Behavior>4 <Servicemetadatahttpgetenabled= "true" />5 <userequestheadersformetadataaddress/>6 </Behavior>7 </servicebehaviors>8 </Behaviors>
Reference
Http://stackoverflow.com/questions/5007270/how-to-change-wsdl-url-from-internal-machine-name-to-public
Http://zamd.net/wcf/2010/01/14/using-request-headers-for-metadata-address.html
https://msdn.microsoft.com/en-us/library/ee816894 (v=vs.110). aspx
Using Request Headers for Metadata Address