Slide show

Web services

Web services

Web Service Structure

Web Service Components

Remote Procedure Call

Web Services Remote Procedure Call

Components of RPC

An RPC system consists of the following pieces

Web Services and Standardisation

RPC requirement SOAP
defined data types defined by SOAP
wire format for data defined by SOAP using XML
wire format for messages defined by SOAP over HTTP
an IDL defined by WSDL
generation of client stubs vendor specific
generation of server stubs vendor specific
linking implementation vendor specific
Address of service URL
Locating service UDDI

Simple Service

WSDL

The WSDL specification looks like


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:tns="urn:Converter" targetNamespace="urn:Converter" name="ConverterService">
    <message name="inchToMMRequest">
        <part name="param1" type="xsd:float"/>
    </message>
    <message name="inchToMMResponse">
        <part name="return" type="xsd:float"/>
    </message>
    <message name="mmToInchRequest">
        <part name="param1" type="xsd:float"/>
    </message>
    <message name="mmToInchResponse">
        <part name="return" type="xsd:float"/>
    </message>
    <message name="java_rmi_RemoteException">
        <part type="xsd:string" name="java_rmi_RemoteException"/>
    </message>
    <message name="com_iona_xmlbus_webservices_ejbserver_ConversionException">
        <part type="xsd:string" name="com_iona_xmlbus_webservices_ejbserver_ConversionException"/>
    </message>
    <portType name="ConverterPortType">
        <operation name="inchToMM">
            <input message="tns:inchToMMRequest" name="inchToMM"/>
            <output message="tns:inchToMMResponse" name="inchToMMResponse"/>
            <fault message="tns:java_rmi_RemoteException" name="java_rmi_RemoteException"/>
        </operation>
        <operation name="mmToInch">
            <input message="tns:mmToInchRequest" name="mmToInch"/>
            <output message="tns:mmToInchResponse" name="mmToInchResponse"/>
            <fault message="tns:java_rmi_RemoteException" name="java_rmi_RemoteException"/>
            <fault
                message="tns:com_iona_xmlbus_webservices_ejbserver_ConversionException" name="com_iona_xmlbus_webservices_ejbserver_ConversionException"/>
        </operation>
    </portType>
    <binding name="ConverterBinding" type="tns:ConverterPortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http/" style="rpc"/>
        <operation name="inchToMM">
            <soap:operation soapAction="" style="rpc"/>
            <input name="inchToMM">
                <soap:body use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </input>
            <output name="inchToMMResponse">
                <soap:body use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </output>
            <fault name="java_rmi_RemoteException">
                <soap:fault name="java_rmi_RemoteException"
                    use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </fault>
        </operation>
        <operation name="mmToInch">
            <soap:operation soapAction="" style="rpc"/>
            <input name="mmToInch">
                <soap:body use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </input>
            <output name="mmToInchResponse">
                <soap:body use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </output>
            <fault name="java_rmi_RemoteException">
                <soap:fault name="java_rmi_RemoteException"
                    use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </fault>
            <fault name="com_iona_xmlbus_webservices_ejbserver_ConversionException">
                <soap:fault
                    name="com_iona_xmlbus_webservices_ejbserver_ConversionException"
                    use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </fault>
        </operation>
    </binding>
    <service name="Converter">
        <port name="ConverterPort" binding="tns:ConverterBinding">
            <soap:address location="http://www.xmlbus.com:9010/ionasoap/servlet/Converter"/>
        </port>
    </service>
</definitions>

Components of WSDL Specification

Data types
Messages
Ports
Bindings
Service

      name: Converter
      
address: http://... ...

WSDL Specification Revisited


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:tns="urn:Converter" targetNamespace="urn:Converter" name="ConverterService">
<message name="inchToMMRequest"> <part name="param1" type="xsd:float"/> </message> <message name="inchToMMResponse"> <part name="return" type="xsd:float"/> </message> <message name="mmToInchRequest"> <part name="param1" type="xsd:float"/> </message> <message name="mmToInchResponse"> <part name="return" type="xsd:float"/> </message> <message name="java_rmi_RemoteException"> <part type="xsd:string" name="java_rmi_RemoteException"/> </message> <message name="com_iona_xmlbus_webservices_ejbserver_ConversionException"> <part type="xsd:string" name="com_iona_xmlbus_webservices_ejbserver_ConversionException"/> </message>
<portType name="ConverterPortType"> <operation name="inchToMM"> <input message="tns:inchToMMRequest" name="inchToMM"/> <output message="tns:inchToMMResponse" name="inchToMMResponse"/> <fault message="tns:java_rmi_RemoteException" name="java_rmi_RemoteException"/> </operation> <operation name="mmToInch"> <input message="tns:mmToInchRequest" name="mmToInch"/> <output message="tns:mmToInchResponse" name="mmToInchResponse"/> <fault message="tns:java_rmi_RemoteException" name="java_rmi_RemoteException"/> <fault message="tns:com_iona_xmlbus_webservices_ejbserver_ConversionException" name="com_iona_xmlbus_webservices_ejbserver_ConversionException"/> </operation> </portType>
<binding name="ConverterBinding" type="tns:ConverterPortType"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http/" style="rpc"/> <operation name="inchToMM"> <soap:operation soapAction="" style="rpc"/> <input name="inchToMM"> <soap:body use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output name="inchToMMResponse"> <soap:body use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> <fault name="java_rmi_RemoteException"> <soap:fault name="java_rmi_RemoteException" use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </fault> </operation> <operation name="mmToInch"> <soap:operation soapAction="" style="rpc"/> <input name="mmToInch"> <soap:body use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output name="mmToInchResponse"> <soap:body use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> <fault name="java_rmi_RemoteException"> <soap:fault name="java_rmi_RemoteException" use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </fault> <fault name="com_iona_xmlbus_webservices_ejbserver_ConversionException"> <soap:fault name="com_iona_xmlbus_webservices_ejbserver_ConversionException" use="encoded" namespace="urn:Converter" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </fault> </operation> </binding>
<service name="Converter"> <port name="ConverterPort" binding="tns:ConverterBinding"> <soap:address location="http://www.xmlbus.com:9010/ionasoap/servlet/Converter"/> </port> </service>
</definitions>

Role of WSDL in Web Services

Apache Axis WSDL Tools

There and Back Again


SOAP


What SOAP is

SOAP Messages

SOAP messages are either

SOAP Request

A SOAP request consists of

SOAP Response

A SOAP response is just like a request, except the body contains the result.

SOAP Message Structure

<?xml version="1.0" ?>
 <env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
   <env:Header>
     <p:oneBlock xmlns:p="http://example.com" env:actor="http://example.com/Log">
     ::::
     </p:oneBlock>
     <q:anotherBlock xmlns:q="http://example.com"
           env:actor="http://www.w3.org/2001/12/soap-envelope/actor/next">
     ::::
     </q:anotherBlock>
     <r:aThirdBlock xmlns:r="http://example.com">
     ::::
     </r:aThirdBlock>
   </env:Header>
   <env:Body >
     ::::
   </env:Body>
 </env:Envelope>

SOAP Header Blocks

SOAP Body for RPC Request

SOAP Body for RPC Response

SOAP HTTP Binding

SOAP HTTP Request


POST /Charging HTTP/1.1
Host: travelcompany.example.org
Content-Type: application/soap; charset="utf-8"
Content-Length: nnnn

<?xml version='1.0' ?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope" >
 <env:Body>
    <m:reserveAndCharge>
        ::::::
    </m:reserveAndCharge>
  </env:Body>
</env:Envelope>
      

SOAP HTTP Response


HTTP/1.1 200 OK
Content-Type: application/soap; charset="utf-8"
Content-Length: nnnn

<?xml version='1.0' ?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope" >
 <env:Body>
    <m:reserveAndChargeResponse>
        ::::::
    </m:reserveAndCharge>
 </env:Body>
</env:Envelope>
      


Calling SOAP Methods


Apache Axis Server

Apache Axis Client - do it yourself


    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
    import javax.xml.namespace.QName;
   
    public class TestClient {
      public static void main(String [] args) {
          try {
              String endpoint =
                       "http://nagoya.apache.org:5049/axis/services/echo";
  
             Service  service = new Service();
             Call     call    = (Call) service.createCall();
  
             call.setTargetEndpointAddress( new java.net.URL(endpoint) );
             call.setOperationName(new QName("http://soapinterop.org/", "echoString"));
             String ret = (String) call.invoke( new Object[] { "Hello!" } );
  
             System.out.println("Sent 'Hello!', got '" + ret + "'");
         } catch (Exception e) {
             System.err.println(e.toString());
         }
     }
   }

Simple converter service



public class SimpleConverter {
    public double inchToMM(double value) {
	return value * 25.4;
    }

    public double mmToInch(double value) {
	return value / 25.4;
    }
};

Simple converter client


package client;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

public class TestSimpleConverter {
    public static void main(String [] args) {
	try {
	    String endpoint =
		"http://localhost:8090/axis/SimpleConverter.jws";
	    
	    Service  service = new Service();
	    Call     call    = (Call) service.createCall();
	    
	    call.setTargetEndpointAddress( new java.net.URL(endpoint) );
	    call.setOperationName(new QName("http://soapinterop.org/", "inchToMM"));
	    Double ret =  (Double) call.invoke( new Object[] { new Double(2.0) } );
	    
	    System.out.println("Sent 'Hello!', got '" + ret + "'");
	} catch (Exception e) {
	    System.err.println(e.toString());
	}
    }
}

Apache Axis client using WSDL


public class Tester
{
    public static void main(String [] args) throws Exception {
        // Make a service
        ConverterInterfaceService service = new ConverterInterfaceServiceLocator();
 
        // Now use the service to get a stub which implements the SDI.
        ConverterInterface port = service.getConverterInterface();
 
        // Make the actual call
        float mm = port.inchToMM(1.0);
    }
}

i18n

Lang information in header block