SOAP - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

SOAP

Description:

Platform independent. language independent. allows you to get around firewalls ... Independent of operating systems, different technologies and programming languages. ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 40
Provided by: saj88
Category:

less

Transcript and Presenter's Notes

Title: SOAP


1
SOAP
  • By
  • Faraz Kadri
  • Sazzad Kamal
  • Tabinda Siddiqi
  • Sajid Ali

2
What is SOAP
  • Communication protocol
  • SOAP stands for Simple Object Access Protocol
  • communication between applications
  • designed to communicate via Internet
  • It is a format for sending messages
  • based on XML

3
Advantages Distadvantages
  • Advantages
  • is simple and extensible
  • Platform independent
  • language independent
  • allows you to get around firewalls
  • SOAP is developed as a W3C standard
  • Disadvantages
  • No security facility

4
Why SOAP?
  • It allows internet communication between
    programs.
  • Todays application communicate using remote
    procedure calls between objects, however http is
    not designed to work with this.
  • Communication between application can be improved
    if http was used.
  • SOAP was created.
  • Independent of operating systems, different
    technologies and programming languages.
  • Key element to Microsoft .NET architecture for
    future internet applications.

5
Versions of SOAP
  • Some major software and hardware companies
    proposed SOAP 1.1 to W3C the SOAP Internet
    protocol that they hope will revolutionize
    application development by connecting graphic
    user interface desktop applications to powerful
    Internet servers using the standards of the
    Internet HTTP and XML.
  • The first public Working Draft on SOAP was
    published by W3C in December 2001. To read more
    about the SOAP activities at W3C please visit our
    W3C tutorial.

6
HTTP Protocol
  • Communicates over TCP/IP
  • Process
  • HTTP client sends a request message to the
    server.
  • POST /item HTTP/1.1
  • Host 189.123.345.239
  • Content-Type text/plain
  • Content-Length 200
  • Server responds back to client.

7
SOAP HTTP Binding
  • A SOAP method is an HTTP request/response that
    complies with the SOAP encoding rules.
  • HTTP XML SOAP
  • A SOAP request could be an HTTP POST or an HTTP
    GET request.
  • The HTTP POST request specifies at least two HTTP
    headers Content-Type and Content-Length.

8
Content-Type Content-Length
  • Content-Type header defines the MIME type for the
    message and the character encoding
  • POST /item HTTP/1.1
  • Content-Type application/soapxml
  • charsetutf-8
  • Content-Length header specifies number of bytes
    in the body of the request/response.
  • POST /item HTTP/1.1
  • Content-Type application/soapxml
    charsetutf-8
  • Content-Length 250

9
SOAP General Rules
  • A SOAP message MUST be encoded using XML
  • A SOAP message MUST use the SOAP Envelope
    namespace
  • A SOAP message MUST use the SOAP Encoding
    namespace
  • A SOAP message must NOT contain a DTD reference
  • A SOAP message must NOT contain XML Processing
    Instructions

10
SOAP DTD
  • lt?xml version"1.0" encoding"UTF-8"?gt
  • lt!ELEMENT Envelope (Header?, Body)gtlt!ELEMENT
    Header (Transaction)gtlt!ELEMENT Body
    (Symbol)gtlt!ELEMENT Transaction
    (PCDATA)gtlt!ELEMENT Symbol (PCDATA)gt
  • lt!ATTLIST Envelope name-space CDATA
    REQUIRED encoding-style CDATA REQUIREDgt
  • lt!ATTLIST Body method CDATA REQUIREDgt
  • lt!ATTLIST Transaction must-understand (0 1)
    REQUIREDgt

11
Basics
  • A SOAP message is an ordinary XML document
    containing the following
  • A required Envelope element that identifies the
    XML document as a SOAP message.
  • An optional Header element that contains header
    information.
  • A required Body element that contains call and
    response information.
  • An optional Fault element that provides
    information about errors that occurred while
    processing the message.

12
Skelton SOAP Message
  • lt?xml version"1.0"?gt
  • ltsoapEnvelope xmlnssoap"http//www.w3.org/2001/
    12/soap
  • envelope" soapencodingStyle"http//www.w3.org/20
    01/12/soap-
  • encoding"gt
  • ltsoapHeadergt
  • ... ...
  • lt/soapHeadergt
  • ltsoapBodygt
  • ... ...
  • ltsoapFaultgt
  • ... ...
  • lt/soapFaultgt
  • lt/soapBodygt
  • lt/soapEnvelopegt

13
Envelope Element
  • ltsoapEnvelope xmlnssoap"http//www.w3.org/2001/
    12/soap-envelop soapencodingStyle"http//www.w
    3.org/2001/12/soap-encoding"gt
  • ...
  • lt/soapEnvelopegt
  • nameSpace (xmlnssoap) defines the Envelope as a
    SOAP Envelope .
  • encodingStyle attribute is used to define the
    data types used in the document.
  • will apply to that element's contents and all
    child elements.
  • SOAP message have no default encodings.

14
Header element
  • An optional Header element that contains header
    information.
  • ltsoapHeadergt
  • ... ...
  • lt/soapHeadergt
  • Contains application specific information (such
    as authentication, payment, etc.) about SOAP
    message.
  • ltsoapHeadergt
  • ltmTrans xmlnsm "http//www.w3school
    s.com/transaction/" soapmustUnderstand"1"gt
  • 234
  • lt/mTransgt
  • lt/soapHeadergt
  • Header element has to be first child element of
    Envelope.

15
Header Cont. (actor)
  • A SOAP message may travel from a sender to a
    receiver by passing different endpoints along the
    message path. Not all parts of the SOAP message
    may be intended for the ultimate endpoint of the
    SOAP message but, instead, may be intended for
    one or more of the endpoints on the message path.
  • The SOAP actor attribute may be used to address
    the Header element to a particular endpoint.
  • Syntax soapactor"URI"
  • ltsoapHeadergt
  • ltmTrans xmlnsm"http//www.w3schools.com/trans
    action/" soapactor"http//www.w3schools.com/app
    ml/"gt
  • 234
  • lt/mTransgt
  • lt/soapHeadergt

16
Header Cont. (mustUnderstand)
  • mustUnderstand attribute can be used to indicate
    whether a header entry is mandatory or optional
    for the recipient to process.
  • If you add mustUnderstand"1" to a child element
    of the Header element it indicates that the
    receiver processing the Header must recognize the
    element. If the receiver does not recognize the
    element it must fail when processing the Header.
  • Syntax soapmustUnderstand"01
  • ltmTrans xmlnsm"http//www.w3schools.com/t
    ransaction/" soapmustUnderstand"1"gt
  • 234
  • lt/mTransgt

17
Body Element
  • A required Body element that contains call and
    response information.
  • ltsoapBodygt
  • ... ...
  • lt/soapBodygt
  • Contains the actual message for ultimate endpoint
    of the message.

18
Body Element Example
  • A client requests price for a fruit.
  • Request
  • ltsoapBodygt
  • ltmGetPrice xmlnsm "http//www.w3sch
    ools.com/prices"gt ltmItemgt
  • Apples
  • lt/mItemgt
  • lt/mGetPricegt
  • lt/soapBodygt
  • Response
  • ltsoapBodygt
  • ltmGetPriceResponse xmlnsm
    "http//www.w3schools.com/prices"gt
    ltmPricegt
  • 1.90
  • lt/mPricegt
  • lt/mGetPriceResponsegt
  • lt/soapBodygt

19
Fault element
  • An optional Fault element that provides
    information about errors that occurred while
    processing the message.
  • An error message from a SOAP message is carried
    inside a Fault element.
  • If a Fault element is present, it must appear as
    a child element of the Body element. A Fault
    element can only appear once in a SOAP message.

20
Fault Element (cont.)
  • SOAP Fault Element
  • The SOAP Fault element has the following sub
    elements
  • Sub Element Description
  • ltfaultcodegt A code for identifying the fault
  • ltfaultstringgt A human readable explanation of
    the fault
  • ltfaultactorgt Information about who caused the
    fault to happen
  • ltdetailgt Holds application specific
    error information related to
  • the Body element
  • SOAP Fault Codes
  • The faultcode values defined below must be used
    in the faultcode element when describing faults
  • Error Description
  • VersionMismatch Found an invalid
    namespace for the SOAP Envelope
    element
  • MustUnderstand An immediate child
    element of the Header element, with the
    mustUnderstand attribute set to "1", was
    not understood
  • Client The message was
    incorrectly formed or contained incorrect
    information
  • Server There was a problem with
    the server so the message could not proceed

21
Fault Example
  • ltSOAP-ENVFaultgt ltfaultcodegt
  • SOAP-ENVClient
  • lt/faultcodegt    ltfaultstringgt
  • Can't find symbol Apples
  • because it is not in the database.
  • lt/faultstringgt
  • lt/SOAP-ENVFaultgt

22
HTTP Protocol
  • Communicates over TCP/IP
  • Process
  • HTTP client sends a request message to the
    server.
  • POST /item HTTP/1.1
  • Host 189.123.345.239
  • Content-Type text/plain
  • Content-Length 200
  • Server responds back to client.

23
SOAP HTTP Binding
  • A SOAP method is an HTTP request/response that
    complies with the SOAP encoding rules.
  • HTTP XML SOAP
  • A SOAP request could be an HTTP POST or an HTTP
    GET request.
  • The HTTP POST request specifies at least two HTTP
    headers Content-Type and Content-Length.

24
Content-Type Content-Length
  • Content-Type header defines the MIME type for the
    message and the character encoding
  • POST /item HTTP/1.1
  • Content-Type application/soapxml
  • charsetutf-8
  • Content-Length header specifies number of bytes
    in the body of the request/response.
  • POST /item HTTP/1.1
  • Content-Type application/soapxml
    charsetutf-8
  • Content-Length 250

25
SOAP Example
  • Server has a method sayGreeting() that a client
    wants to call with a String argument and the
    result is returned.
  • public class SoapService
  • public SoapService()
  • / Method to be called by client /
  • public String sayGreeting(String name)
    return "Hello "name

26
Before we move further
  • The server needs to know how to handle the SOAP
    requests coming in from clients.
  • This is achieved with the help of Deployment
    Descriptors.
  • Deployments Descriptors contains all the
    information needed to identify and process a
    client SOAP request.

27
Deployment Descriptor
  • The Deployment Descriptor basically contains the
    following things
  • The id of the service.
  • The provider type.
  • The scope of the service (Request/Session/Applica
    tion).
  • The provider class or script name.
  • The method(s) that the client wants to access.
  • The fault listener (optional)

28
Back to SOAP Example
  • In our example, servlet is given the following
    XML document to let it know how to handle the
    request.
  • ltisdservice xmlnsisd"http//xml.apache.org/xml-
    soap/deployment" id"urngreetingService"gt
  • ltisdprovider type"java" scope"Request
    methods"sayGreeting"gt
  • ltisdjava class
  • "sam.soap.service.SoapService"
    static"false"/gt
  • lt/isdprovidergt
  • lt/isdservicegt

29
The Client
  • In order to make a method call to server, the
    client side
  • builds up a Call object which represents the RPC
    in Java
  • SOAP.
  • Call call new Call()
  • Essential ingredients in Call.
  • The name of the service at the server.
    SoapService object in the example.
  • call.setTargetObjectURI(
  • "urngreetingService")

30
  • Essential ingredients in Call continued
  • The name of the RPC method in server.
    sayGreeting() in the example.
  • call.setMethodName("sayGreeting")
  • Information about encoding style.
  • call.setEncodingStyleURI(
  • Constants.NS_URI_SOAP_ENC)
  • Data (argument) to be passed to the RPC method.
  • Vector params new Vector()
    params.addElement(new Parameter("name",
    String.class, name, null))
  • call.setParams(params)

31
The Client (continued)
  • Invoking Call method
  • Now that we have build the Call object, we can
    invoke it to get a response from the server
  • Response res call.invoke(
  • new URL(urlString), "")

32
  • Parsing the Response
  • The Response object contains the result of the
    RPC call made by the Call object.
  • if( res.generatedFault() false)
  • Parameter retValue res.getReturnValue
    ()
  • Object value retValue.getValue()
    System.out.println(value)
  • else
  • System.out.println("The fault is
    res.getFault().getFaultString())

33
High level implementation
  • How are the soap xml messages generated and dealt
    with

34
Underlying mechanism
  • Apache soap API
  • The Call object in the client
  • The soap handler servlet in the server

35
How did it all work together
  • Flow of messages

36
SOAP-Java Data Types
  • Definitions
  • In SOAPs context we need to undertand
  • Serializer
  • Java class that converts a specific Java
    object to XML.
  • Deserializer
  • Java class that converts specific XML to a
  • Java object.

37
Simple data-types in SOAP
  • There are several data types already defined by
    Java for serialization/deserialization in SOAP.

38
Simple data-types in SOAP
  • QName
  • - a special data type (class) that can be
    user-defined.
  • - provided a serialization/deserialization
  • class (QNameSerializer).
  • - limitations of how the class can be defined.
    Must follow Java Bean model for classes i.e.
    empty constructor, getters/setters for all the
    variables.

39
Custom data-types in SOAP
  • The real power and flexibility of SOAP compared
    to other RPC models can only be revealed if we
    had the complete freedom to define and pass our
    own data types. To do this
  • We need to write our own Serializers/Deserializers
    .
  • Writing our own (De)serializers will have
    flexibility of defining data-type in our own way
    without conforming to Java Bean specifications.
  • Need to make sure there is a copy of the
    (De)serializers at both client and the server end.
Write a Comment
User Comments (0)
About PowerShow.com