Showing posts with label WSDL. Show all posts
Showing posts with label WSDL. Show all posts

Friday, June 3, 2011

Wcf Wsdl Generation and Including Schemas

For some reason, when you browse to the WSDL for a ServiceContract you do not get included Schema in the WSDL Types.

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.