2. Team Members V. Dinusha S. Saatviga S.Y.Y.D. Wickramasinghe D. Wijethilake 3/16/2009 2
3. Contents 3/16/2009 3 Introduction SOAP SOAP Elements SOAP Syntax SOAP Envelope SOAP Header SOAP Body SOAP Fault SOAP Http Binding Example Conclusion Reference
4. Introduction 3/16/2009 4 SOAP is a communication protocol Lets applications exchange information over HTTP. Communication between applications via internet Format for sending messages Independence Platform Language Based on XML, yet simple and extensible Today’s Apps Communicate using RPC (DCOM , CORBA) RPC represents a compatibility and security problem. firewalls and proxy servers will normally block this kind of traffic. Better way is to communicate through HTTP that is supported by all Internet browsers and servers.
5. SOAP Elements 3/16/2009 5 A SOAP message is an ordinary XML Document Envelope - Identifies the XML document as a SOAP message Header - Contains header information Body - Contains call and response information Fault - Contains errors and status information
6. SOAP Syntax 3/16/2009 6 A SOAP message MUST Be encoded using XML Use the SOAP Envelope namespace Use the SOAP Encoding namespace Not contain a DTD reference NOT contain XML Processing Instructions Skeleton SOAP Message <?xml version="1.0"?> <soap:Envelope xmlns:soap=http://www.w3.org/2001/12/soap-envelope soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header> ….. </soap:Header> <soap:Body> <soap:Fault> ... ... </soap:Fault> </soap:Body> </soap:Envelope>
7. SOAP Envelope 3/16/2009 7 The root element of a SOAP message Defines the XML document as a SOAP message xmlns:soap Namespace Defines the Envelope as a SOAP Envelope. Different namespace The application generates an error Discards the message encodingStyle Attribute Defines the data types used in the document. May appear on any SOAP element Will apply to element's contents and all child elements A SOAP message has No default encoding <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> ... Message information goes here ... </soap:Envelope>
8. SOAP Header 3/16/2009 8 Optional & If present - Must be the first child element of the Envelope Application-specific information of the SOAP Message Authentication, Payment, etc. All immediate child elements of Header must be namespace-qualified Attributes – Defines how a recipient should process the SOAP message mustUnderstand Attribute Is Header entry Mandatory/Optional for the recipient to process? <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header> <m:Trans xmlns:m="http://www.w3schools.com/transaction/" soap:mustUnderstand="1“ >234 </m:Trans> </soap:Header> ... ... </soap:Envelope>
9. SOAP Header cont. 3/16/2009 9 actorAttribute Addresses the Header element to a specific endpoint encodingStyleAttribute Defines data types used in the document May appear on any SOAP element Will apply to that element's contents and all child elements A SOAP message has no default encoding <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header> <m:Trans xmlns:m="http://www.w3schools.com/transaction/" soap:actor="http://www.w3schools.com/appml/" >234 </m:Trans> </soap:Header> ... ... </soap:Envelope>
10. SOAP Header cont. 3/16/2009 10 actorAttribute Addresses the Header element to a specific endpoint encodingStyleAttribute Defines data types used in the document May appear on any SOAP element Will apply to that element's contents and all child elements A SOAP message has no default encoding soap:encodingStyle="URI" <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header> <m:Trans xmlns:m="http://www.w3schools.com/transaction/" soap:actor="http://www.w3schools.com/appml/" >234 </m:Trans> </soap:Header> ... ... </soap:Envelope>
11. SOAP Body 3/16/2009 11 The actual SOAP message for the ultimate endpoint of the message Immediate child elements may be namespace-qualified Request Response <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Body> <m:GetPrice xmlns:m="http://www.w3schools.com/prices"> <m:Item>Apples</m:Item> </m:GetPrice> </soap:Body> </soap:Envelope> <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Body> <m:GetPriceResponse xmlns:m="http://www.w3schools.com/prices"> <m:Price>1.90</m:Price> </m:GetPriceResponse> </soap:Body> </soap:Envelope>
12. SOAP Fault 3/16/2009 12 Optional yet indicates Error Messages Must appear as a child element of the Body Can only appear once in a SOAP message Sub elements: <faultcode> Code for identifying the fault VersionMismatchFound An invalid namespace for the SOAP Envelope MustUnderstand Immediate Header child element not understood (mustUnderstand -"1") Client Message was incorrectly formed /contained incorrect info Server Message not proceed due to server error <faultstring> A human readable explanation of the fault <faultactor> Who caused the fault <detail> Application specific error information related to the Body
13. SOAP Http Binding 3/16/2009 13 Http HTTP communicates over TCP/IP An HTTP client connects to an HTTP server using TCP After establishing a connection, client can send an HTTP request to server The server then processes the request and sends an HTTP response back to the client. The response contains a status code that indicates the status of the request If the server could not decode the request, it could have returned an error message POST /item HTTP/1.1 Host: 189.123.345.239 Content-Type: text/plain Content-Length: 200 200 OK Content-Type: text/plain Content-Length: 200 400 Bad Request Content-Length: 0
14. SOAP Http Binding cont. 3/16/2009 14 SOAP = HTTP + XML A SOAP method HTTP request/response Complies with the SOAP encoding rules A SOAP request HTTP POST (Specifies at least two HTTP headers [Type, Length]) HTTP GET Content-Type Optional MIME type for the message Character encoding (used for the XML body of the request/response) Content-Length The number of bytes in the body of the request/response POST /item HTTP/1.1 Content-Type: application/soap+xml; charset=utf-8 Content-Length: 250
15. SOAP Http Binding cont. 3/16/2009 15 SOAP = HTTP + XML A SOAP method HTTP request/response Complies with the SOAP encoding rules A SOAP request HTTP POST (Specifies at least two HTTP headers [Type, Length]) HTTP GET Content-Type Optional MIME type for the message Character encoding (used for the XML body of the request/response) Content-Length The number of bytes in the body of the request/response POST /item HTTP/1.1 Content-Type: application/soap+xml; charset=utf-8 Content-Length: 250
16. Example import java.util.Calendar; import java.util.GregorianCalendar; import javax.jws.WebService; @WebService(name = "GetDatesWS", serviceName = "GetDatesWS") public class GetDates { public GetDates() { } public Calendar getDate() { return Calendar.getInstance(); } public Calendar getDateHence( intdaysHence) { GregorianCalendarmyCalendar = new GregorianCalendar(); myCalendar.add(GregorianCalendar.DATE, daysHence); return myCalendar; } }
22. Conclusion 3/16/2009 22 SOAP is a communication protocol SOAP = Http + XML Platform & Language Independent Able to penetrate firewalls Elements: Envelope Header Body Fault