Version 2

    Generating/writing WSDL & jaxrpc-mapping.xml

     

    This is the most painful part. Today you have to write the wsdl file by hand. You can choose to start from scratch or you can start with the wsdl generated by the JWSDP. Here we're using the latter.

     

    Generate the rpc/encoded wsdl

     

    With ant, you will need to run a target with a wscompile call:

    ...
         <taskdef name="wscompile" classname="com.sun.xml.rpc.tools.ant.Wscompile">
              <classpath refid="server.cp"></classpath>
         </taskdef>
    ...
    
              <!-- generate the wsdl from the service interface -->
              <wscompile
                   verbose="true"
                   xPrintStackTrace="true"   
                   keep="true"
                   fork="true"
                   base="classes/server"
                   server="true"
                   sourcebase="generated/src/server"
                   mapping="generated/jaxrpc-mapping.xml"
                   nonclassdir="generated/wsdl"
                   config="conf/config-service.xml">
    
                   <classpath>
                        <pathelement location="classes/server"></pathelement>
                        <path refid="server.cp"></path>
                   </classpath>
              </wscompile>
    
    
    
    

     

    This will produce a MyService.wsdl file. It uses the following config-service.xml file (config from the service class).

     

    <configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
      <!--
           |     Used in first place to generate the default wsdl from where we will start
         -->
      <service name="MyService"
        targetNamespace="http://org.jboss.ws.example.attachment/MyService"
        typeNamespace="http://org.jboss.ws.example.attachment/MyService/types"
        packageName="org.jboss.ws.example.attachment.stub">
        <interface name="org.jboss.ws.example.attachment.MyService"></interface>
      </service>  
    </configuration>
    

     

    Modify the WSDL to fit our needs

     

    Namespaces: add the mime namespace.

     

    <definitions name="MyService" 
         targetNamespace="http://org.jboss.ws.example.attachment/MyService" 
         xmlns:tns="http://org.jboss.ws.example.attachment/MyService" 
         xmlns="http://schemas.xmlsoap.org/wsdl/" 
         xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
         xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
         xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"> <-- here

     

    Type: no types

    <types></types>

     

    Message: note that DataHandler arg & return type are declared as xsd:hexBinary

      <message name="MyService_myService">
        <part name="mimepart" type="xsd:hexBinary"></part>
      </message>
      <message name="MyService_myServiceResponse">
        <part name="result" type="xsd:hexBinary"></part>
      </message>

     

    Port Type: nothing special

      <portType name="MyService">
        <operation name="myService" parameterOrder="mimepart">
          <input message="tns:MyService_myService"/>
          <output message="tns:MyService_myServiceResponse"></output>
        </operation>
      </portType>

     

    RPC: today only RPC style is possible for attachment. Next release will enable the document style.

      <binding name="MyServiceBinding" type="tns:MyService">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"></soap:binding>
    ...
    

     

    Operation with Multipart declaration: note that even if we only use attachment arg and return value, a body element should be defined. A soap message should always provide a body part. Also, note the literal use definition.

        <operation name="myService">
          <soap:operation soapAction=""></soap:operation>
          <input>
         <mime:multipartRelated>
                <mime:part>
                  <soap:body use="literal" namespace="http://org.jboss.ws.example.attachment/MyService"></soap:body>
                </mime:part>
                <mime:part>
                  <mime:content part="mimepart" type="text/plain"></mime:content>
                </mime:part>
            </mime:multipartRelated>
         </input>
          <output>
           <soap:body use="literal" namespace="http://org.jboss.ws.example.attachment/MyService"></soap:body>
         <mime:multipartRelated>
                <mime:part>
                  <soap:body use="literal" namespace="http://org.jboss.ws.example.attachment/MyService"></soap:body>
                </mime:part>
                <mime:part>
                  <mime:content part="result" type="text/plain"></mime:content>
                </mime:part>
              </mime:multipartRelated>
          </output>
         </operation>
    

     

     

    Generating the jaxrpc-mapping.xml file

    With the new wsdl, you can generate the jaxrpc-mappng.xml file. This time the wscompile looks like:

         <!-- generate the jaxrpc-mapping.xml from the our wsdl -->
         <wscompile
              verbose="true"
              xPrintStackTrace="true"   
              keep="true"
              fork="true"
              base="classes/server"
              server="true"
              features="" 
              sourcebase="generated/src/server"
              mapping="generated/jaxrpc-mapping.xml"
              config="conf/config-wsdl.xml">
    
              <classpath>
                   <pathelement location="classes/server"></pathelement>
                   <path refid="server.cp"></path>
              </classpath>
         </wscompile>
    

     

    and it uses the following config-wsdl.xml file (config from the wsdl).

    <configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
      <!--
           |     Used in a second step to generate jaxrpc-mapping.xml
         -->
      <wsdl location="conf/MyService.wsdl"
        packageName="org.jboss.ws.example.attachment">
      </wsdl>
    </configuration>