You are on page 1of 48

Understanding SOAP

Kenn Scribner Mark C. Stiver

Copyright 2000 Kenn Scribner and Mark C. Stiver

SOAP
Simple Object Access Protocol

Copyright 2000 Kenn Scribner and Mark C. Stiver

Waves of the Internet

Copyright 2000 Kenn Scribner and Mark C. Stiver

Waves of the Internet


1st Wave: Engineering research
Interconnecting systems at the TCP/IP level Network packets, addressing, routing

Copyright 2000 Kenn Scribner and Mark C. Stiver

Waves of the Internet


2nd Wave: Engineer to System
Publishing of data (FTP) Remote system access (Telnet) Information discovery (Gopher) Difficult to use tools

Copyright 2000 Kenn Scribner and Mark C. Stiver

Waves of the Internet


3rd Wave: Consumer to System
Web browsers Electronic Business systems (shopping carts) Java applets Presentation based

Copyright 2000 Kenn Scribner and Mark C. Stiver

Waves of the Internet


4th Wave: Application to Application (B2B)
Services on the web Service advertisement/discovery Process integration Information based

Copyright 2000 Kenn Scribner and Mark C. Stiver

Motivations
Heterogeneous systems must be able to communicate Binary protocols dont always work
CORBA, DCOM, etc. dont work well through firewalls Nobody can agree on a standard binary format (usually due to platform-related issues) Were dealing with many heterogeneous environments (MVS, Unix, Windows NT, Linux, PalmOS, etc.) Component runtimes differ Security models differ (Kerberos, NTLM, OSF-DCE)

Copyright 2000 Kenn Scribner and Mark C. Stiver

What we need...
Standards (as usual) A firewall-friendly protocol An extensible framework Low cost of entry Loose coupling Platform and programming language agnostic technology

Copyright 2000 Kenn Scribner and Mark C. Stiver

What do we have to work with?


XML - An extensible framework that is easy-to-use and has a low-cost of entry HTTP/SMTP - Industry accepted transport protocols that are already supported by Enterprise servers and are friendly with firewalls

Copyright 2000 Kenn Scribner and Mark C. Stiver

Enter SOAP...

Copyright 2000 Kenn Scribner and Mark C. Stiver

What SOAP is...


SOAP is a specification for defining...
an encoding style that uses XML to represent information graphs a standard way to move XML with HTTP rules for passing messages error (fault) definition a medium for performing Remote Procedure Calls (RPC) one layer in a multi-layer architecture
Copyright 2000 Kenn Scribner and Mark C. Stiver

What SOAP isnt...


A silver bullet A definition of interface semantics A security model A run-time definition

Copyright 2000 Kenn Scribner and Mark C. Stiver

SOAP Encoding
Envelope package Header/Body pattern
Similar to how HTTP works
Header

Body

Copyright 2000 Kenn Scribner and Mark C. Stiver

Header
Out-of-band information such as
Authentication information Message routes Logging Transaction flow

Basically, any information that is disjoint from interface methods/messages

Copyright 2000 Kenn Scribner and Mark C. Stiver

Body
Interface-specific information such as
RPC method name and parameters Serialized objects (instances of types) Messages

Copyright 2000 Kenn Scribner and Mark C. Stiver

Simple Example
<Envelope> <Header> <transId>1234</transId> </Header> <Body> <Add> <a>3</a> <b>4</b>

c = Add(a, b)

</Add>
</Body> </Envelope>
Copyright 2000 Kenn Scribner and Mark C. Stiver

System Flow (HTTP)


<Envelope> <Header> <transId>1234</transId> </Header> <Body> <Add> <a>3</a> <b>4</b> </Add> </Body> </Envelope>

<Envelope> <Header> <transId>1234</transId> </Header> <Body> <AddResponse> <c>7</c> </AddResponse> </Body> </Envelope>

Copyright 2000 Kenn Scribner and Mark C. Stiver

So, whats missing?


Avoiding ambiguity in messages
XML Namespaces

Describing data types


XML Schemas

Binding to a transport
HTTP header fields

Copyright 2000 Kenn Scribner and Mark C. Stiver

XML Namespaces
Default namespace
<Book xmlns=Some-URI>

<Author>Tom Clancy</Author>
</Book>

Qualifying names with prefixes


<b:Book xmlns:b=Some-URI> <Author>Tom Clancy</Author> </b:Book>

Unqualified element

URI: A string that can contains a string that is assumed unique.


URLs are one form of URI since domain names must be unique! http://www.somecompany.com/xml
Copyright 2000 Kenn Scribner and Mark C. Stiver

XML Schemas
Type defines
Hierarchies Structure Constraints (facets)

Simple types
Integers, strings, floats, time, etc.

Compound types
Arrays, structures
Copyright 2000 Kenn Scribner and Mark C. Stiver

XML Schema Example


<?xml version="1.0"?> <schema targetNamespace="http://example.com/stockquote.xsd" xmlns="http://www.w3.org/1999/XMLSchema"> <element name="TradePriceRequest"> <complexType> <all> <element name="tickerSymbol" type="string"/> </all> </complexType> </element> <element name="TradePrice"> <complexType> <all> <element name="price" type="float"/> </all> </complexType> </element> </schema>
Copyright 2000 Kenn Scribner and Mark C. Stiver

Actual SOAP Request


<SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/> <SOAP-ENV:Header> <t:transId xmlns:t=http://a.com/trans>1234</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:Add xmlns:m=http://a.com/Calculator> <a xsi:type=integer>3</a> <b xsi:type=integer>4</b> </m:Add> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Copyright 2000 Kenn Scribner and Mark C. Stiver

Actual SOAP Request


<SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/> <SOAP-ENV:Header> <t:transId xmlns:t=http://a.com/trans>1234</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:Add xmlns:m=http://a.com/Calculator> <a xsi:type=integer>3</a> <b xsi:type=integer>4</b> </m:Add> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Copyright 2000 Kenn Scribner and Mark C. Stiver

Actual SOAP Response


<SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/> <SOAP-ENV:Header> <t:transId xmlns:t=http://a.com/trans>1234</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:AddResponse xmlns:m=http://a.com/Calculator> <c xsi:type=integer>7</c> </m:AddResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

Copyright 2000 Kenn Scribner and Mark C. Stiver

Actual SOAP Response


<SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/> <SOAP-ENV:Header> <t:transId xmlns:t=http://a.com/trans>1234</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:AddResponse xmlns:m=http://a.com/Calculator> <c xsi:type=integer>7</c> </m:AddResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

Copyright 2000 Kenn Scribner and Mark C. Stiver

Analyzing a Request

<SOAP-ENV:Envelope

Scopes the message to the SOAP namespace

xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/> ...etc... </SOAP-ENV:Envelope>

Establishes the type of encoding that is used within the message

Copyright 2000 Kenn Scribner and Mark C. Stiver

Analyzing a Request
...etc... <SOAP-ENV:Header>

Qualifies transId

<t:transId xmlns:t=http://a.com/trans>1234</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body>

Establishes the interface/method

<m:Add xmlns:m=http://a.com/Calculator> <a xsi:type=integer>3</a> <b xsi:type=integer>4</b> </m:Add> </SOAP-ENV:Body> ...etc...

Describes parameter types

Copyright 2000 Kenn Scribner and Mark C. Stiver

Requests as RPC
Method element immediately follows <Body> Parameters are serialized in left-to-right order Normally, xsi:type is used to provide type information (XML Schemas) Method element NS qualifies entire message
<SOAP-ENV:Body> <m:Add xmlns:m=http://a.com/Calculator>

<a xsi:type=integer>3</a>
<b xsi:type=integer>4</b> </m:Add> </SOAP-ENV:Body>
Copyright 2000 Kenn Scribner and Mark C. Stiver

Analyzing a Response
<SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/> <SOAP-ENV:Header> <t:transId xmlns:t=http://a.com/trans>1234</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:AddResponse xmlns:m=http://a.com/Calculator> <c xsi:type=integer>7</c> </m:AddResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

Response typically uses method name with Response appended

Copyright 2000 Kenn Scribner and Mark C. Stiver

Serializing Types

Copyright 2000 Kenn Scribner and Mark C. Stiver

Values and References


By value - Add([in] int a, [in] int b);
<m:Add xmlns:m=http://a.com/Calculator> <a xsi:type=integer>3</a> <b xsi:type=integer>4</b> </m:Add>

By reference - Square([in, out] int &a);


<m:Add xmlns:m=http://a.com/Calculator> <a href=#arg /> </m:Add> <a id=arg xsi:type=integer>8</a>

Copyright 2000 Kenn Scribner and Mark C. Stiver

Arrays
Arrays
int a[3] = {1, 2, 3}; b = Add([in]a);
<m:Add xmlns:m=http://a.com/Calculator xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/> <a SOAP-ENC:arrayType=xsd:int[3]> <SOAP-ENC:int>1</SOAP-ENC:int> <SOAP-ENC:int>2</SOAP-ENC:int> <SOAP-ENC:int>3</SOAP-ENC:int> </a> </m:Add>

Copyright 2000 Kenn Scribner and Mark C. Stiver

Applying SOAP to a Transport

Copyright 2000 Kenn Scribner and Mark C. Stiver

Binding to HTTP (Request)


POST /Calculator.pl HTTP/1.0 Host: www.a.com Accept: text/* Content-type: text/xml Content-length: nnnn SOAPAction: http://www.a.com/Calculator#Add {CR}{LF} <SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/> <SOAP-ENV:Header> <t:transId xmlns:t=http://a.com/trans>1234</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:Add xmlns:m=http://a.com/Calculator> <a xsi:type=integer>3</a> <b xsi:type=integer>4</b> </m:Add> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Copyright 2000 Kenn Scribner and Mark C. Stiver

Binding to HTTP (Response)


HTTP/1.0 200 OK Content-type: text/xml Content-length: nnnn {CR}{LF} <SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/> <SOAP-ENV:Header> <t:transId xmlns:t=http://a.com/trans>1234</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:AddResponse xmlns:m=http://a.com/Calculator> <c xsi:type=integer>7</c> </m:AddResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

Copyright 2000 Kenn Scribner and Mark C. Stiver

SOAPAction
This is my intent! POST /Calculator.pl HTTP/1.0 Host: www.a.com Accept: text/* Content-type: text/xml Content-length: nnnn SOAPAction: http://www.a.com/Calculator#Add {CR}{LF} <SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/> <SOAP-ENV:Header> <t:transId xmlns:t=http://a.com/trans>1234</t:transId> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:Add xmlns:m=http://a.com/Calculator> ...etc...
Copyright 2000 Kenn Scribner and Mark C. Stiver

SOAP Faults
HTTP/1.0 200 OK Content-type: text/xml Content-length: nnnn {CR}{LF} <SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring>Internal Application Error</faultstring> <detail xmlns:f=http://www.a.com/CalculatorFault> <f:errorCode>794634</f:errorCode> <f:errorMsg>Divide by zero</f:errorMsg> </detail> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Copyright 2000 Kenn Scribner and Mark C. Stiver

Where are we?

Application

Web Service

Interface Semantics
Envelope/Header/Body

Interface Semantics
Envelope/Header/Body

Message Encoding

SOAP

Message Encoding

Transport (e.g. HTTP) TCP/IP

Transport (e.g. HTTP) TCP/IP

Copyright 2000 Kenn Scribner and Mark C. Stiver

Miscellaneous Topics

Copyright 2000 Kenn Scribner and Mark C. Stiver

Security
SOAP spec says nothing Delegated to other levels
Transport (HTTPS/SSL) Virtual Private Networks (VPNs)

Included in interface semantics Needs standardization

Copyright 2000 Kenn Scribner and Mark C. Stiver

Service Description
SDL (Service Description Language) MS v1.0 SCL (Service Contract Language) MS v2.0 NASSL (Network Accessible Service Specification Language) IBM v1.0 WSDL (Web Services Description Language)
Exposes XML Schema Describes Transport Bindings Describes Encoding Scheme
Copyright 2000 Kenn Scribner and Mark C. Stiver

WSDL
Includes
Data types Message structure Operations Protocol bindings Addresses Services

Copyright 2000 Kenn Scribner and Mark C. Stiver

See Examples...

Copyright 2000 Kenn Scribner and Mark C. Stiver

Service Discovery
UDDI (Universal Description, Discovery and Integration)
Defines interface semantics Database of services (yellow, white, green pages) Uses SOAP messages
Query Inquiry Publishing

ADS (Advertisement and Discovery of Services)


File that describes your service
Copyright 2000 Kenn Scribner and Mark C. Stiver

Service Discovery

Copyright 2000 Kenn Scribner and Mark C. Stiver

Summary
Integrating processes via the web is key XML and HTTP are the enabling technologies SOAP defines the encoding scheme WSDL describes the service UDDI advertises the service

Copyright 2000 Kenn Scribner and Mark C. Stiver

Resources
DevelopMentor - www.develop.com/soap SOAP mail list - discuss.develop.com W3C protocols - www.w3.org/2000/xp/ IBM - alphaworks.ibm.com Microsoft - msdn.microsoft.com Apache - xml.apache.org

Copyright 2000 Kenn Scribner and Mark C. Stiver

You might also like