Simple Object Access Protocol

4,715 views

Published on

Published in: Technology
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,715
On SlideShare
0
From Embeds
0
Number of Embeds
29
Actions
Shares
0
Downloads
414
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Simple Object Access Protocol

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

×