Failing to generate WSDL from an Azure-hosted WCF service behind SSL

Error: Cannot obtain Metadata from http://example.com/api/service.svc?wsdl

Setup

  • 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.

Solution

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!

 

2 thoughts on “Failing to generate WSDL from an Azure-hosted WCF service behind SSL

  1. Matt

    Thanks for this; my exact symptoms (a bugger to google for too) and this fixed the problem. Curses to the people who thought referring universally to http throughout the bindings (leading one to think that WCF config files discuss https in the same manner that they do http), and having a default serviceMetaData tag in all the example configs that doesn’t mention the httpsGetEnabled attribute at all

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.