Slide show

Web services

Jan Newmarch
School of Network Computing
Monash University
Email: jan@newmarch.name
Home page: http://jan.netcomp.monash.edu.au

Web services - content

Web services

Web services

Scope of tutorial

Gartner software state

Gartner regularly publishes a graph on the state of software. The latest (at August 2002) is

Web Service Structure

Web Service Components

Example Web Services

The site XMethods (www.xmethods.com) is an open site for registering Web services. It includes

Web Service Environmental Support

Web services are basically RPC across port 80. They require the following environmental support

Web Service Standards Requirements

Ordinary Procedure Call

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

Missing parts

These are coming (?), but aren't here yet

WSDL


Role of Specification Languages

Simple Service

CORBA

A CORBA IDL specification would look like


    interface Converter {
        float inchToMM(in float value);
        float mmToInch(in float value);
    };

Java RMI

A Java RMI specification would look like


    public interface Converter implements Remote {
        public float inchToMM(float value)
                     throws RemoteException;
        public float mmToInch(float value)
                     throws RemoteException;
    }

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>

WSDL Versions

Role of WSDL in Web Services

Apache Axis WSDL Tools

There and Back Again

Conclusion


SOAP


What SOAP Claims to be

What SOAP is

What SOAP isn't

XML Descriptions

XML DTDs

XML DTDs (Document Type Definitions) are good for describing document structure e.g.

XML Schema

XML Schema Standard Data Types


SOAP Messages

SOAP messages are either

Java mapping of data types

Most XML standard data type are represented by a Java data type

XML Java
boolean boolean
byte byte
dateTime java.util.Calendar
double double
float float
int int
integer java.math.BigInteger
string String

Some types can't be represented since they don't exist in Java, such as unsigned int. If a type can be "nillable" (that is, have a nil value) and it would be a Java primitive type, then it is wrapped in a Java class such as Integer.

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


Roll Your Own

Perl SOAP::Lite

Apache Axis Server

Apache Axis service and Perl client

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());
         }
     }
   }

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);
    }
}

Browser access to Web services

Conclusion


Session management


HTTP and sessions

Cookies and other hacks

Sessions and SOAP

What is involved

Conclusion


Security


General

XML Encryption

Breaking the SOAP specifications

Conclusion


UDDI


UDDI (Universal Description, Discovery and Integration)

Registry Entry

UDDI and WSDL

Public/private Registries

Private Registries

Access to Registries

Perl client

Java Client

Summary

References


Jan Newmarch (http://jan.netcomp.monash.edu.au)
jan.newmarch@infotech.monash.edu.au
Last modified: Wed Oct 22 08:47:23 EST 2003
Copyright ©Jan Newmarch