23

I'm troubling into an issue... I'm trying to find a way to generate a single wsdl document from my WCF service, i.e. without any link to external documents. I've used FlatWsdl to remove all xsd:import links, bou my generated wsdl still contains a link to an external wsdl document via a wsdl:import declaration:

<wsdl:import namespace="http://myurl/mynamespace"  
             location="http://myserver/myservice.svc?wsdl=wsdl0"/>  

This document actually contains all inlined xsd schemas, so... there's a way to inline also this external wsdl document, in order to have a single wsdl?

Thanks a lot for any kind of help.

D_Guidi
  • 698
  • 1
  • 5
  • 10

6 Answers6

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
12

(EDIT: Previous answer about FlatWSDL deleted, because as you pointed out it was about eliminating xsd:import not wsdl:import.)

Look at this blogpost: Control generated WSDL in WCF

"... There is always one WSDL generated for one target namespace URI ..."

Do you have different namespace for ServiceContract, DataContract, ServiceBehavior, etc. ?

Vizu
  • 1,871
  • 1
  • 15
  • 21
  • You can also add this as a behavior to a service using the standard service host factory - see my links. – marc_s Jun 12 '09 at 07:27
  • I've used FlatWsdl, but this flattening only xsd:import and not wsdl:import... maybe I've made a mistake, but looking at the code only XSD are changed :( – D_Guidi Jun 12 '09 at 07:47
  • 9
    that link is dead, here it is via waybackmachine: http://web.archive.org/web/20100723044037/http://www.pluralsight-training.net/community/blogs/kirillg/archive/2006/06/18/28380.aspx – Marcus Swope Apr 12 '12 at 15:14
  • 1
    the root cause is explained in the above link, the simplest way to resolve this issue is using ?singlewsdl. – Dino Liu Aug 05 '16 at 07:22
  • Copy of the dead link: https://viviendo20.wordpress.com/2017/02/15/control-generated-wsdl-in-wcf-namespaces/ – Alfonso Tienda Feb 15 '17 at 10:22
4

You could also use the WCFExtras project it has an extension to create a single WSDL-file.

WCFExtras

A collection of useful WCF extensions including Soap Header support, WSDL documentation and more.

The WCF platform is very extensible and allows you to easily add features that are not part of the core product. This project contains some extensions I needed in a WCF based project:

  • SOAP Header support for WCF Adding WSDL
  • Documentation from Source Code XML Comments
  • Override SOAP Address Location URL
  • Single WSDL file for better compatibility with older SOAP tools.

http://wcfextras.codeplex.com/

Jochen
  • 1,488
  • 16
  • 21
  • I've take a look at WCFExtras, but from my investigations (maybe I'm wrong) the feature "Single WSDL file" inlines XSD's but not external WSDL's... maybe my problem is here: "... There is always one WSDL generated for one target namespace URI ..." as suggested from Vizu – D_Guidi Jun 12 '09 at 15:03
2

my problem was in endpoint definitions, that are in tempuri.org namespace adding bindingNamespace to endpoint declarations fix my problem. thanks to all for help :)

D_Guidi
  • 698
  • 1
  • 5
  • 10
1

This is a late answer, but I had the same problem with a few of our WCF services. If you're on .NET 4.5, like the earlier answer, use ?singleWSDL, but if you're not targeting .NET 4.5 then I added the following to my web.config to fix the issue...

<useRequestHeadersForMetadataAddress>
  <defaultPorts>
    <add port="80" scheme="http" />
    <add port="443" scheme="https" />
  </defaultPorts>
</useRequestHeadersForMetadataAddress>

This goes in your behavior. That way I didn't have to flatten the WSDL because all references were to MyURL instead of MyServer.

Hope this helps others with a similar issue.

Jim
  • 6,753
  • 12
  • 44
  • 72
0

In addition to Jim's answer above, if you're using C# code to configure a WCF ServiceHost directly:

using System.ServiceModel.Configuration;

and when setting up your ServiceHost:

UseRequestHeadersForMetadataAddressBehavior urh = new UseRequestHeadersForMetadataAddressBehavior();
serviceHost.Description.Behaviors.Add(urh);

I struggled to find this information online, as simple as it is. Hopefully helps someone in a similar situation.