Monday, 19 December 2011

WSDL Binding customization example


<jaxws:bindings
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxws http://java.sun.com/xml/ns/jaxws/wsdl_customizationschema_2_0.xsd
http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
wsdlLocation="http://www.webservicex.net/stockquote.asmx?WSDL">

  <!-- JAXWS -->
  <jaxws:package name="com.company.jaxwstest.client"/>

  <!-- JAXB -->
  <!-- <jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema"> --> 
  <jaxws:bindings node="//xsd:schema">
    <jxb:schemaBindings>
      <jxb:package name="com.company.jaxwstest.client.jaxb"/>
    </jxb:schemaBindings>
  </jaxws:bindings>
 
</jaxws:bindings>

wsgen & wsimport @ ant

<project>

  <!-- Define classpath -->

  <property name="glassfish.dir" value="C:\Programme\Java\Glassfish3\glassfish" />
  <property name="glassfish.modules.dir" value="${glassfish.dir}\modules" />

  <path id="glassfish.modules.path">
    <fileset dir="${glassfish.modules.dir}">
      <include name="**/*.jar" />
    </fileset>
  </path>

  <!-- Define tasks -->

  <taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen">
    <classpath refid="glassfish.modules.path" />
  </taskdef>

  <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
    <classpath refid="glassfish.modules.path" />
  </taskdef>

  <!-- Define targets -->

  <target name="server">
    <wsgen keep="true" verbose="true" xendorsed="true" genwsdl="true" fork="true"
      sei="com.company.jaxwstest.server.JavaToWsdl"
      classpath="build/classes"
      destdir="build/classes"
      resourcedestdir="WebContent/WEB-INF/wsdl"
      sourcedestdir="src"/>
  </target>

  <target name="client">
    <wsimport keep="true" verbose="true" xendorsed="true" fork="true"
      wsdl="http://www.webservicex.net/stockquote.asmx?WSDL"
      destdir="build/classes"
      sourcedestdir="src"
      package="com.company.jaxwstest.client"
      binding="binding.xml"/>
  </target>

</project>

Friday, 16 December 2011

Wrapper/Bare/RPC example

RPC Java:

@WebMethod(operationName = "hello")
public String sayHello(
@WebParam(name = "firstname") String nachname,
@WebParam(name = "lastname") String vorname)

RPC WSDL:

<message name="hello">
  <part name="firstname" type="xsd:string" />
  <part name="lastname" type="xsd:string" />
</message>

<message name="helloResponse">
  <part name="return" type="xsd:string" />
</message>

<portType name="testService">
  <operation name="hello">
    <input message="tns:hello" />
    <output message="tns:helloResponse" />
  </operation>
</portType>

Document/Wrapped Java (like RPC, plus generated "jaxws" wrapper classes):

@WebMethod(operationName = "hello")
public String sayHello(
@WebParam(name = "firstname") String nachname,
@WebParam(name = "lastname") String vorname)

Document/Wrapped WSDL:

<types>
  <xs:element name="hello" nillable="true" type="tns:sayHello"/>
  <xs:element name="helloResponse" nillable="true" type="tns:sayHelloResponse"/>

  <xs:complexType name="sayHello">
    <xs:sequence>
      <xs:element name="firstname" type="xs:string" minOccurs="0"/>
      <xs:element name="lastname" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="sayHelloResponse">
    <xs:sequence>
      <xs:element name="return" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</types>

<message name="hello">
  <part name="parameters" element="tns:hello"/>
</message>

<message name="helloResponse">
  <part name="parameters" element="tns:helloResponse"/>
</message>

<portType name="testService">
  <operation name="hello">
    <input message="tns:hello"/>
    <output message="tns:helloResponse"/>
  </operation>
</portType>

Document/Bare Java (no generated class, with additional "Person" bean):

@WebMethod(operationName = "hello")
public String sayHello(Person p)

Document/Bare WSDL:

<types>
  <xs:element name="hello" nillable="true" type="tns:person"/>
  <xs:element name="helloResponse" nillable="true" type="xs:string"/>

  <xs:complexType name="person">
    <xs:sequence>
      <xs:element name="nachname" type="xs:string" minOccurs="0"/>
      <xs:element name="vorname" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</types>

<message name="hello">
  <part name="hello" element="tns:hello"/>
</message>

<message name="helloResponse">
  <part name="helloResponse" element="tns:helloResponse"/>
</message>

<portType name="testService">
  <operation name="hello">
    <input message="tns:hello"/>
    <output message="tns:helloResponse"/>
  </operation>
</portType>