cs603 communication mechanisms: soap 25 january 2002
TRANSCRIPT
![Page 1: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/1.jpg)
CS603Communication Mechanisms:
SOAP
25 January 2002
![Page 2: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/2.jpg)
SOAP:Simple Object Access Protocol
• Overview– Goal: RPC protocol that works over wide area networks
• Interoperable• Language independent
– Problem: Firewalls• Solution: HTTP/XML
• History– Work started in 1998 – produced XML-RPC
• Vendor-led, big Microsoft influence– 1999: SOAP 1 – type system from XML Schemas
• More vendors– 2001: Picked up by W3C – XML Protocol working group
• Now called XP (XML Protocol)• Microsoft using it for their .NET replacement for DCOM
![Page 3: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/3.jpg)
SOAP
• Advantages– Goes anywhere
• http is universal protocol
– Open standard• Based on XML, defined by W3C working group
• Disadvantages– Type semantics must be defined
• Extra work for users
– Pure text protocol• High cost to translate at endpoints• Eats bandwidth
![Page 4: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/4.jpg)
SOAPComponents
• Client side: Ability to generate http calls and listen for responseSounds like a browser!
• Server:– Listen for HTTP– Bind to procedure– Respond with HTTP
First and last are Web Server!
![Page 5: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/5.jpg)
SOAP call
<soap:Envelope>
<soap:Body>
<xmlns:m="http://www.stock.org/stock" />
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
![Page 6: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/6.jpg)
SOAP response
<soap:Envelope>
<soap:Body>
<xmlns:m="http://www.stock.org/stock" />
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>
![Page 7: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/7.jpg)
SOAP Template<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><soap:Header>
User-created definitions, e.g. language of message</soap:Header><soap:Body>
Call and arguments, or results for a response</soap:Body><soap:Fault>
Errors (response only)</soap:Fault>
</soap:Envelope>
![Page 8: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/8.jpg)
Key SOAP Attributes
• Header– Actor: URI of intended recipient– encodingStyle: URI of definition of types used– mustUnderstand: True if receiver MUST process
element
• Fault– <faultcode>: VersionMismatch, MustUnderstand,
Client, Server– <faultstring>: Error as a string– <faultactor>: Who caused it– <detail>: Additional information
![Page 9: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/9.jpg)
Building a client:Apache SOAP
• Open source web server driven by IBM
• SOAP available as integral part
• Java packages to interface between java programs and SOAP
• Also supports javascript SOAP clients/servers
![Page 10: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/10.jpg)
SOAPSample Client
import java.net.URL; import java.util.Vector; import org.apache.soap.SOAPException; import org.apache.soap.Constants;import org.apache.soap.Fault; import org.apache.soap.rpc.Call; import org.apache.soap.rpc.Parameter; import org.apache.soap.rpc.Response;public class Client {public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost:8080/apache-soap/servlet/rpcrouter"); Call call = new Call();call.setTargetObjectURI("urn:Hello");call.setMethodName(“HelloWorld");call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); Vector params = new Vector();params.addElement(new Parameter("name", String.class, “Argument”, null)); call.setParams(params);
![Page 11: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/11.jpg)
SOAPSample Client
Response resp = null; try { resp = call.invoke(url, ""); }catch( SOAPException e ) {
System.err.println("Caught SOAPException (" + e.getFaultCode() + "): " +e.getMessage());
System.exit(-1);} // Check the response.if( !resp.generatedFault() ) {
Parameter ret = resp.getReturnValue();Object value = ret.getValue(); System.out.println(value);
} else {Fault fault = resp.getFault(); System.err.println("Generated fault: ");System.out.println (" Fault Code = " + fault.getFaultCode()); System.out.println (" Fault String = " + fault.getFaultString());
}}
![Page 12: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/12.jpg)
SOAPServer code
public class HelloServer{ public String HelloWorld(String name) {
System.out.println(name);return "Hello World!”;
} }
![Page 13: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/13.jpg)
Activating the server
• org.apache.soap.server.ServiceManagerClienthttp://localhost:8080/apache-soap/servlet/rpcrouter deploy DeploymentDescriptor.xml
• DeploymentDescripter.xml:<isd:service
xmlns:isd="http://xml.apache.org/xml-soap/deployment" id="urn:Hello"><isd:provider type="java" scope="Application“ methods=“HelloWorld">
<isd:java class="HelloServer" static="false"/></isd:provider>
</isd:service>
![Page 14: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/14.jpg)
Client-generated call<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<soap:Header></soap:Header><soap:Body>
<ns1:HelloWorldxmlns:ns1="Hello"soap:encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"><name xsi:type="xsd:string">Arguments</name>
</ns1:HelloWorld></soap:Body>
</soap:Envelope>
![Page 15: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/15.jpg)
Server-generated response<soap:Envelope
xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<soap:Body><ns1:HelloWorld
xmlns:ns1="Hello"soap:encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"><return xsi:type="xsd:string">Hello World!</return>
</ns1:HelloWorld></soap:Body>
</soap:Envelope>
![Page 16: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/16.jpg)
DCE vs. Java RMI vs. SOAP
• Philosophy– DCE RPC: generic interface
• Define “clean sheet” system• Port to variety of protocols/systems/languages
– Java RMI: “proprietary” interface• Coupled to single language/run time system• Port entire system to multiple platforms
– SOAP: single standard interface• Define interface on single protocol• Pick protocol that is universal
![Page 17: CS603 Communication Mechanisms: SOAP 25 January 2002](https://reader035.vdocuments.mx/reader035/viewer/2022080914/56649f425503460f94c61414/html5/thumbnails/17.jpg)
Which do I use?
• All-JAVA world? RMI
• Need security / fault tolerance? RPC
• Need to get through firewalls? SOAP
• Performance?
• Objects as arguments?