Error: Cannot obtain Metadata from http://example.com/api/service.svc?wsdl
- WCF Service with SOAP, JSON and XML endpoints where the SOAP endpoint is a basicHttpBinding rather than a wsHttpBinding
- All service endpoints behind SSL
- SecuritySwitch installed and rewrite rules enabled to force all requests through to SSL where available
- AspNetCompatibilityEnabled = true, MultipleSiteBindingsEnabled = true
- <useRequestHeadersForMetadataAddress> element added to service behaviour with default ports http -> 80 and https -> 443
- Trying to add a service reference in Visual Studio yields a number of errors:
HTTP GET Error URI: http://example.com/api/Service.svc?wsdl The document at the url https://example.com/api/Service.svc?wsdl was not recognized as a known document type. The error message from each known type may help you fix the problem: - Report from 'XML Schema' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'. - Report from 'https://example.com/api/Service.svc?wsdl' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'. - Report from 'DISCO Document' is 'Discovery document at the URL https://example.com/api/Service.svc?disco could not be found.'. - The document format is not recognized. - Report from 'WSDL Document' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.
Bugger. However, notice that the initial request URL is http, and the WSDL endpoint is https. Trying to navigate manually to the ?wsdl URL failed and just re-rendered the ‘You have created a service’ welcome page.
In my case the solution was to set httpsGetEnabled = true (in addition to httpGetEnabled=true) on the serviceMetadata tag for the service behaviour in question.
Hopefully Google’ll find this for me the next time I do it!