Tuesday, December 20, 2011

WSDL and advertising your service

Okay, so now you've got a web service, and someone wants to use it.  How do they know how to do that?  WSDL for SOAP advertises the methods and parameters used / returned such that anyone can interact with your service.

If you navigate to: http://localhost:8080/SOAPDemoWebService/SOAPDemoWebService?WSDL, you will see:

The + symbols are areas you could expand to see the rest of the info.  I closed them so I could get a reasonable image for display.  From this, you can see that each method is described in terms of its request parameters and its response parameters.

WSDL has two sides to it.  One, is the definition of your services.  The other is for auto discovery of your services.  You can use WSDL to define your REST services even though WSDL wasn't designed for REST, but it may be a little much for just defining your RESTful services.  You may be better off just writing up the description in a readable page that anyone can view and implement.  You won't get auto-discovery by doing that, but the real world use case for auto-discovery is not really there.

For the SOAP service, how did we define the WSDL to get transmitted?  Well, fortunately, NetBeans auto generated the file for us from the web definitions already put in place, so there was no additional effort needed to create the WSDL.  But, we can review the files in case we had to generate them ourselves:

/JSFDemoApp/Web Pages/WEB-INF/wsdl/localhost_8080/SOAPDemoWebService/SOAPDemoWebService.wsdl

<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.1.1-b09 (branches/2.1-6834; 2011-07-16T17:14:48+0000) JAXWS-RI/2.2.5-promoted-b04 JAXWS/2.2. --><!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.1.1-b09 (branches/2.1-6834; 2011-07-16T17:14:48+0000) JAXWS-RI/2.2.5-promoted-b04 JAXWS/2.2. -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.sample.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service.sample.com/" name="SOAPDemoWebService">
<types>
<xsd:schema>
<xsd:import namespace="http://service.sample.com/" schemaLocation="http://localhost:8080/SOAPDemoWebService/SOAPDemoWebService?xsd=1"/>
</xsd:schema>
</types>
<message name="find">
<part name="parameters" element="tns:find"/>
</message>
<message name="findResponse">
<part name="parameters" element="tns:findResponse"/>
</message>
<message name="remove">
<part name="parameters" element="tns:remove"/>
</message>
<message name="removeResponse">
<part name="parameters" element="tns:removeResponse"/>
</message>
<message name="create">
<part name="parameters" element="tns:create"/>
</message>
<message name="createResponse">
<part name="parameters" element="tns:createResponse"/>
</message>
<portType name="SOAPDemoWebService">
<operation name="find">
<input wsam:Action="http://service.sample.com/SOAPDemoWebService/findRequest" message="tns:find"/>
<output wsam:Action="http://service.sample.com/SOAPDemoWebService/findResponse" message="tns:findResponse"/>
</operation>
<operation name="remove">
<input wsam:Action="http://service.sample.com/SOAPDemoWebService/removeRequest" message="tns:remove"/>
<output wsam:Action="http://service.sample.com/SOAPDemoWebService/removeResponse" message="tns:removeResponse"/>
</operation>
<operation name="create">
<input wsam:Action="http://service.sample.com/SOAPDemoWebService/createRequest" message="tns:create"/>
<output wsam:Action="http://service.sample.com/SOAPDemoWebService/createResponse" message="tns:createResponse"/>
</operation>
</portType>
<binding name="SOAPDemoWebServicePortBinding" type="tns:SOAPDemoWebService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="find">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="remove">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
<operation name="create">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="SOAPDemoWebService">
<port name="SOAPDemoWebServicePort" binding="tns:SOAPDemoWebServicePortBinding">
<soap:address location="http://localhost:8080/SOAPDemoWebService/SOAPDemoWebService"/>
</port>
</service>
</definitions>


/JSFDemoApp/Web Pages/WEB-INF/wsdl/localhost_8080/SOAPDemoWebService/SOAPDemoWebService.xsd_1.xsd

<?xml version='1.0' encoding='UTF-8'?><!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Metro/2.1.1-b09 (branches/2.1-6834; 2011-07-16T17:14:48+0000) JAXWS-RI/2.2.5-promoted-b04 JAXWS/2.2. --><xs:schema xmlns:tns="http://service.sample.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://service.sample.com/">


<xs:element name="create" type="tns:create"/>


<xs:element name="createResponse" type="tns:createResponse"/>


<xs:element name="find" type="tns:find"/>


<xs:element name="findResponse" type="tns:findResponse"/>


<xs:element name="part" type="tns:part"/>


<xs:element name="remove" type="tns:remove"/>


<xs:element name="removeResponse" type="tns:removeResponse"/>


<xs:complexType name="find">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>


<xs:complexType name="findResponse">
<xs:sequence>
<xs:element name="return" type="tns:part" minOccurs="0"/>
</xs:sequence>
</xs:complexType>


<xs:complexType name="part">
<xs:sequence>
<xs:element name="id" type="xs:long" minOccurs="0"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="parent" type="xs:string" minOccurs="0"/>
<xs:element name="subParts" type="xs:string" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>


<xs:complexType name="create">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="parentName" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>


<xs:complexType name="createResponse">
<xs:sequence>
<xs:element name="return" type="tns:part" minOccurs="0"/>
</xs:sequence>
</xs:complexType>


<xs:complexType name="remove">
<xs:sequence>
<xs:element name="id" type="xs:long" minOccurs="0"/>
</xs:sequence>
</xs:complexType>


<xs:complexType name="removeResponse">
<xs:sequence>
<xs:element name="return" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:schema>



No comments:

Post a Comment