200 likes | 292 Views
CSE 190: Internet E-Commerce. Lecture 19: SOAP, WAP. Machines that talk. We have web services for people How do we enable machines that inter-operate? XML as a way of representing data But need a mechanism for communicating remote procedure calls . Example:
E N D
CSE 190: Internet E-Commerce Lecture 19: SOAP, WAP
Machines that talk • We have web services for people • How do we enable machines that inter-operate? • XML as a way of representing data • But need a mechanism for communicating remote procedure calls. • Example: • Travel site providing driving directions to your hotel
Motivations • Heterogeneous systems must be able to communicate • Binary protocols don’t always work • CORBA, DCOM, etc. don’t work well through firewalls • Nobody can agree on a standard binary format (usually due to platform-related issues) • We’re dealing with many heterogeneous environments (MVS, Unix, Windows NT, Linux, PalmOS, etc.) • Component runtimes differ • Security models differ (Kerberos, NTLM, OSF-DCE)
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
SOAP • SOAP: a method for doing RPC using XML to encode the parameters to our functions • For application to application integration • SOAP: Simple Object Access Protocol • Why not DCOM, CORBA, JNI? • Don’t natively work over HTTP, need custom ports • Even when they do, not human-readable • SOAP pitfall • Argument marshaling less efficient • A W3C Standard
SOAP Example: Request <soap:Envelope> <soap:Body> <xmlns:m= "http://www.amzn.org/books" /> <m:GetBookPrice> <m:BookName>Fast Food Nation</m:BookName> </m:GetBookPrice> </soap:Body> </soap:Envelope>
SOAP Example: Response <soap:Envelope> <soap:Body> <xmlns:m="http://www.amzn.org/books" /> <m:GetBookPriceResponse> <m:Price>34.5</m:Price> </m:GetBookPriceResponse> </soap:Body> </soap:Envelope>
SOAP Example: Error <soap:Fault> <faultcode>0x800700E</faultcode> <faulstring>Unknown book</faultstring> </soap:Fault>
Envelope contains Header Body Header is optional Out-of-band information such as… Authentication information Message routes Logging Transaction flow Body contains XML body of RPC call SOAP Structure
SOAP Example 2 <?xml version="1.0" encoding="UTF-8" ?> <env:Envelope xmlns:env="http://www.w3.org/2001/09/soap-envelope"> <env:Header> <n:alertcontrol xmlns:n="http://example.org/alertcontrol"> <n:priority>1</n:priority> <n:expires>2001-06-22T14:00:00-05:00</n:expires> </n:alertcontrol> </env:Header> <env:Body> <m:alert xmlns:m="http://example.org/alert"> <m:msg>Pick up Mary at school at 2pm</m:msg> </m:alert> </env:Body> </env:Envelope>
Values and References • By value - Add([in] int a, [in] int b); • By reference - Square([in, out] int &a); <m:Add xmlns:m=“http://a.com/Calculator”> <a xsi:type=“integer”>3</a> <b xsi:type=“integer”>4</b> </m:Add> <m:Add xmlns:m=“http://a.com/Calculator”> <a href=“#arg” /> </m:Add> <a id=“arg” xsi:type=“integer”>8</a>
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>
SOAP over 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>
SOAP over 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>
WSDL(Web Services Description Language)Describing available SOAP Service(First, data types passed to web services) http://example.com/stockquote/stockquote.xsd <?xml version="1.0"?> <schema targetNamespace="http://example.com/stockquote/schemas" xmlns="http://www.w3.org/2000/10/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>
WSDL (cot’d)(Then, the actual methods and expected response structure) http://example.com/stockquote/stockquote.wsdl <?xml version="1.0"?> <definitions name="StockQuote" targetNamespace="http://example.com/stockquote/definitions" xmlns:tns="http://example.com/stockquote/definitions" xmlns:xsd1="http://example.com/stockquote/schemas" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <import namespace="http://example.com/stockquote/schemas" location="http://example.com/stockquote/stockquote.xsd"/> <message name="GetLastTradePriceInput"> <part name="body" element="xsd1:TradePriceRequest"/> </message> <message name="GetLastTradePriceOutput"> <part name="body" element="xsd1:TradePrice"/> </message> <portType name="StockQuotePortType"> <operation name="GetLastTradePrice"> <input message="tns:GetLastTradePriceInput"/> <output message="tns:GetLastTradePriceOutput"/> </operation> </portType> </definitions>
SOAP + WSDL:Half of what .NET is about • .NET: Building web services as components that may be re-used in other applications • Hasn’t happened yet
.NET (cot’d) • Second half of .NET: A set of language tools for developing web services and Win32 languages • New languages: C#, VB.NET • What’s new: Common Language Runtime • Allows multiple languages to use the same runtime libraries • Development tools: ASP.NET, ADO.NET • ASP.NET: Ignore the HTTP request/response structure and statelessness issues • Structure web sites as if you were assembling form code • ADO.NET: Disconnected record-sets (in memory DB)
WAP, WML • WAP: Wireless Application Protocol • WML: Wireless Markup Language • Allows simple pages to be viewed by your mobile phone browser • Through a proxy, pages returned via normal HTTP • WML is not HTML • Standardized by the WAP forum
WML Example • WML is an XML document <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card id="HTML" title="HTML Tutorial"> <p> Our HTML Tutorial is an award winning tutorial from W3Schools. </p> </card> <card id="XML" title="XML Tutorial"> <p> Our XML Tutorial is an award winning tutorial from W3Schools. </p> </card> </wml>