For example: Here's a basic demo Wcf Service.
Notice the link to view the actual WSDL file for this service.
This is what the WSDL file looks like :
Notice how the <wsdl:Types /> element is empty. Ideally a WSDL document should be the one stop shop for describing the service.
To view the schemas of the data contracts and other types used by the service you need to add other parameters to the URL as follows:
Xsd0 shows the service actions, the methods and their parameters.
Xsd1 shows the standard scalar types used, ie strings, arrays etc.
Xsd2 shows the custom data contract types defined and used in the service.
Xsd3 (not shown above) will show any enumeration definitions that you have included in operation contracts.
All these schemas can be copied into the <wsdl:types /> element or imported into the element as follows:
<wsdl:types>
<xsd:schema targetNamespace="http://wcf.rees.biz/CalculatorDemo/2011/06/Imports">
<xsd:import schemaLocation="http://localhost:55401/CalculatorService.svc?xsd=xsd0" namespace="http://wcf.rees.biz/CalculatorDemo/2011/06" />
<xsd:import schemaLocation="http://localhost:55401/CalculatorService.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
<xsd:import schemaLocation="http://localhost:55401/CalculatorService.svc?xsd=xsd2" namespace="http://wcf.rees.biz/CalculatorDemo/2011/06/" />
</xsd:schema>
</wsdl:types>
As an alternative to using a browser to explore the WSDL for a service you can use the SVCUTIL to extract the WSDL and XSD and save them locally.
SVCUTIL /t:metadata http://url_to_service_here.
This will extract the WSDL and all related XSD files onto your local disk in the current folder.
As a courtesy to any third party you are engaging with and co-developing a service always ensure you give them schema's in the WSDL.
Hi Ben,
ReplyDeletegreat article. I've have implemented a lot of asmx web services and now I'm moving to WCF.
Is it possible to set the wsdl / xsd constraints and restrinctions using the DataMember/DataContract attributes?
Simple answer is no (not that I know of). I have heard of some people editing the resulting XSD schema's inside the WSDL. But this will put you in a dangerous situation when you want to make service changes and forget to update the WSDL. I would recommend using a IParameterInspector to inspect individual incoming operation arguments and validate them. You can invent some of your own attributes to describe how to validate them (ie Regex or similar) then look for the presence of those attributes inside your implementation of IParameterInspector. HTH
ReplyDeleteCheers
Ben
WCF and .Net 4.5 has the option to create a single WSDL file out of the box with no effort or third party libraries. Finally!
ReplyDeleteHere's another technique worth considering:
ReplyDeletehttp://blogs.msdn.com/b/dotnetinterop/archive/2008/09/23/flatten-your-wsdl-with-this-custom-servicehost-for-wcf.aspx
It provides you with a custom service host (or factory).