6

How do I create a single flat WSDL file (with no external references from within) from an existing WCF service? This WSDL will be used (imported) into an older programming technology that only supports BasicHttpBinding. Please address your answer to a beginner.

Sam
  • 2,663
  • 10
  • 41
  • 60

2 Answers2

22

You can now do this natively in .net 4.5 (beta). There is an option (?singleWsdl instead of ?wsdl) for telling the service to output everything in a single wsdl document. More info on the new stuff here: http://msdn.microsoft.com/en-us/library/dd456789(v=vs.110).aspx

Irwin
  • 12,551
  • 11
  • 67
  • 97
  • 6
    +1 Someone should implement the "Export WSDL" context menu option in Visual Studio. Right-click on the service library project, Export WSDL, check some preferences and Save As. Why is the WSDL file not treated like any other component of the project? – Sam Dec 29 '11 at 01:09
  • In the event of an IWsdlExportExtension you actually need to run the code first. – mhand Feb 20 '15 at 18:03
  • 1
    ?singleWsdl works perfectly. This one should be the best answer. – AntonK Apr 30 '15 at 00:56
14

I had to do this, too. And I used the WSDLExtras library. It's not too big of a deal.

Here is a step by step instruction for using it:

  1. Download the WCFExtras from here, extract it and add a reference to it in VS.

  2. Add a reference to your Web.config/App.config like this:

    <system.serviceModel>
        <extensions>
            <behaviorExtensions>
                <add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
            </behaviorExtensions>
        </extensions>
    </system.serviceModel>
    
  3. Add the extension to your endpoint behavior and set the singleFile attribute to true

    <endpointBehaviors>
         <behavior name="singleFileEndpointBehavior">
             <wsdlExtensions singleFile="True" />
         </behavior>
    </endpointBehaviors>
    
  4. Use the endpointbehavior for your service-endpoint.

    <endpoint address="YourEndPoint/Address" binding="YourBinding" behaviorConfiguration="singleFileEndpointBehavior" contract="IYourContract">
    

This worked fine for me. You can also download a full example from the WCFExtras project page: ProjectPage

Edit: For the sake of completeness: You can use the ''?singleWsdl'' query parameter since .NET 4.5 as stated in Irwins answer. See the link he posted for more details.

Philipp Grathwohl
  • 2,726
  • 3
  • 27
  • 38
  • What if we don't have access to the source to make these modifications? – Sebastien Martin Apr 07 '11 at 20:55
  • 1
    @Sebastien, I'd suggest creating another WCF service to act as the intermediary between your client and the service you want to use but can't modify. Then you can have full control of the WSDL for the intermediary. Or ask the developers of the other service to provide "backward compatibility" for older SOAP toolkits. I went with the first option. – Sam Apr 18 '11 at 23:50
  • @Sam This is a lot of work for something that is seemingly simple. I instead wrote a short python script to flatten one of these WSDLs. It's not perfect, but I'll keep improving it and welcome any suggestions: https://github.com/sebmartin/FlatWSDL – Sebastien Martin Apr 20 '11 at 17:45