I'm using PowerShell to access a WCF SOAP service. This is all hunky dory going straight at the WCF endpoint host. I am using:
$request = New-WebServiceProxy -uri ${using:endpoint}"?wsdl" -class "MyService" -namespace "MS"
I have a new server that is sitting behind an F5 local traffic manager (LTM). When I attempt the same thing, I am getting errors because the WSDL that is being returned contains links to the server itself, which is inaccessible, and not to the LTM endpoint.
This results in:
The document was understood, but it could not be processed.
- The WSDL document contains links that could not be resolved.
- There was an error downloading 'http://myhost/MyService/MyService.svc?xsd=xsd0'.
- Unable to connect to the remote server
- No connection could be made because the target machine actively refused it 192.168.1.1:80
+ CategoryInfo : InvalidOperation: (http://192.168.1...ervice.svc?wsdl:Uri) [New-WebServiceProxy], Invalid
OperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.NewWebServiceProxy
+ PSComputerName : localhost
What do I need to get the LTM host/IP to appear in the WSDL? Is there some setting in the service's web.config that I am missing?
Add the following to your web.config file:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<useRequestHeadersForMetadataAddress />
Without the above, WCF will pick up the url to present from IIS. You could also add host headers to the binding of the site/application that WCF is hosted in, it will use that instead.