简体   繁体   中英

WCF: how to generate a single WSDL document, without WSDL:import?

I'm troubling into an issue... I'm trying to find a way to generate a single wsdl document from my WCF service, ie 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.

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

(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. ?

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/

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 :)

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.

You need to add some extra behaviours etc.

See these articles here:

http://my-tech-talk.blogspot.com/2008/07/adding-flatwsdl-to-wcf-webservice.html

http://blogs.thinktecture.com/cweyer/archive/2007/05/10/414840.aspx

There are several different ways of achieving this.

Marc

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM