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…
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)
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.
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