Flatten WCF WSDL

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

When working on hybrid solutions with WCF you will definitely get a requirement to share your WSDL. All of you who are working on such project already know or even feel that this can be a serious issue.
WSDL typically describes the contract and configuration of one Web Service. Unfortunately when working with WCF you will figure out that downloaded WSDL is a file which reference number of types shared in several schema document (unflatten WSDL). In fact we should not care about this as long we have the access to the service URL. The problem is if the URL of the service is not reachable or if the service even not exist yet. This is exactly how typical project runs. One or more teams agree the contract (WSDL) which should be created and shared to teams.

In this it is easiest way for WCF developer to build the mock service which exactly implement defined contract. But, how to send that WSDL to somebody else?
by using of SVCUTIL it is possible to download all metadata locally.
This is how it works:

svcutil /t:metadata http://youserviceusr?wsdl

This command downloads all related documents locally. After you have all needed documents you can compress them and send to other team.  Unfortinatelly this will not work. You should never send downloaded metadata to anybody, because they are not usable. Here is why…

image

Open any of downloaded documents which contains reference to other document (import element). You will notice that attribute location points to the original URL suffixed with schema name. Practically that means that somebody who wants to generate proxies from these metadata will be implicitly redirected to the original URL. Remember our assumed constrains was “There is no running service or/and there is no access to it”.

To make this clear. Imagine you are the guy who has received these documents. If you want to create WCF proxies from them you would type:

svcutil tempuri.org.wsdl  (where tempuri.org.wsdl is the name of the root metadata document downloaded by previous command)

This command will fail, because no any of references hidden in downloaded documents can be resolved. This seems to be bug in SVCUTIL. I have figured out that this is not the bug. It is by design of SVCUTIL. This is painful, but why somebody decided to build such design of /t:metadata?
The reason for this is a huge limitation of SVCUTIL. This tool is not capable of referencing of any metadata document which does not starts with http://…
I have tried to replace  all imports to file:///MyService.wsdl, but without success.

To make this working there are few tools like http://wcfextras.codeplex.com/. Unfortunately I always had some difficulties and decided to do it different way. In general I don’t like to make any change in my service to flatten XML. This is what all these tools require.

I wrote the simple program called FlattenXml.exe which downloads all metadata from service as it is and automatically replace all references from http://…/DOC to wsdl/DOC.
This means that all references will point to relative URL /wsdl/referencedDocumentName.xy. With knowing this you can simply create a web application in IIS with physical location to folder with downloaded metada data.

Here is one example what to do:

Export, Prepare and Send metadata

1. Execute flattenxml.exe to download and correct metadata references

    FlattenXml http://localhost/service/servicefile.svc?wsdl OutputFolder

2. Compress all data and send them to other team

Create proxies from exported metadata

1. The team which has received metadata will uncompress all files in one folder like c:\temp\metadata.

2. The team will have to create an application in IIS with the  name WSDL (this is hardcoded name in tool and it cannot be changed)
     image

3. Now the team can create the proxy

svcutil http://localhost/wsdl/therootmetadatadocument.wsdl

The root document has always extension WSDL. Sometimes there is another WSDL document. Note that only one document reference to onother one. If you are not sure take a look in file map.xml which has been generated in output folder. This is how this file looks in my case. I have used service with very complex contract defined by EPCIS specification.
image

Lookup the URL with “?wsdl” in URL .(blue fame). The name of the root file is in filename attribute (red frame). So, to create metadata browse for
svcutil http://localhost/wsdl/TrackingServiceSoap.wsdl

The tool can be downloaded here.
http://developers.de/media/p/167733/download.aspx


Posted Oct 09 2011, 12:08 AM by Damir Dobric
Filed under: ,

Comments

Damir Dobric wrote re: Flatten WCF WSDL
on 10-12-2011 12:39

The version 1.0.2.2 has been posted today.

Damir Dobric Posts wrote Flatten WSDL 1.0.2.4
on 02-17-2012 22:23

Few moths ago I have presented the tool for my session WCF Internals session at Advance Developer Conference

S. Shetty wrote re: Flatten WCF WSDL
on 05-07-2012 15:02

Thanks a lot! Exactly what I was looking for.

Nuri wrote re: Flatten WCF WSDL
on 06-05-2012 9:12

Very good article.  I think it potnis out a big weakness in WCF in terms of interoperability.  Packaging the WSDL into separate files just won't work with many clients.  I wasn't entirely happy with the solution on Christian Weyer's page either although it is one way to solve the problem.  Ideally one should be able to specify the flat WSDL just through configuration.It seems like a step back from asmx in terms in inter-operability.  At the end of the day, I think plain old xml and schemas is probably the best answer for true interoperability.

Damir Dobric wrote re: Flatten WCF WSDL
on 06-15-2012 21:37

Note that the link above is offline, because there is a new version: developers.de/.../flatten-wsdl-1-0-2-4.aspx

developers.de is a .Net Community Blog powered by daenet GmbH.