Copyright 1999 – 2003 Ellis Horowitz SOAP 1 SOAP.

Slides:



Advertisements
Similar presentations
Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.
Advertisements

Web Service Ahmed Gamal Ahmed Nile University Bioinformatics Group
SOAP.
Web Services Web Services are the basic fundamental building blocks of invoking features that can be accessed by an application program. The accessibility.
CIS 375—Web App Dev II SOAP.
XML in the real world (2) SOAP. What is SOAP? ► SOAP stands for Simple Object Access Protocol ► SOAP is a communication protocol ► SOAP is for communication.
Topics Acronyms in Action SOAP 6 November 2008 CIS 340.
SE 370: Programming Web Services Week 4: SOAP & NetBeans Copyright © Steven W. Johnson February 1, 2013.
Web Services Darshan R. Kapadia Gregor von Laszewski 1http://grid.rit.edu.
Web Services Nasrullah. Motivation about web service There are number of programms over the internet that need to communicate with other programms over.
Presentation 7 part 2: SOAP & WSDL. Ingeniørhøjskolen i Århus Slide 2 Outline Building blocks in Web Services SOA SOAP WSDL (UDDI)
Web Services Jeffrey Miller California State University Los Angeles Winter 2003.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
Slide 1 EE557: Server-Side Development Lecturer: David Molloy Room: XG19 Mondays 10am-1pm Notes:
EEC-681/781 Distributed Computing Systems Lecture 7 Wenbing Zhao (Lecture nodes are based on materials obtained from
SOAP Chandra Dutt Yarlagadda Introduction  Why ?  What ?  How ?  Security Issues in SOAP  Advantages  Uses  Conclusion.
XML Web Services ASP.NET. Overview of Web Services (Page 1) Web Service – Part or all of a Web application that is publicly exposed so that other applications.
INTRODUCTION TO WEB SERVICES CS 795. What is a Web Service ? Web service is a means by which computers talk to each other over the web using HTTP and.
CS 415 N-Tier Application Development By Umair Ashraf July 6,2013 National University of Computer and Emerging Sciences Lecture # 9 Introduction to Web.
Web Services CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Processing of structured documents Spring 2003, Part 6 Helena Ahonen-Myka.
TP2653 Adv Web Programming SOAP and WSDL. SOAP Simple Object Access Protocol – Lightweight XML-based messaging protocol – A protocol for accessing a Web.
1 EIE424 Distributed Systems and Networking Programming –Part II 2. XML-RPC.
SOAP Tutorial Ching-Long Yeh 葉慶隆 Department of Computer Science and Engineering Tatung University
Web Services: XML & SOAP Presented by: Davor Svetinovic Date: July 22, 2002.
Outline  Enterprise System Integration: Key for Business Success  Key Challenges to Enterprise System Integration  Service-Oriented Architecture (SOA)
Web Services (SOAP, WSDL, and UDDI)
James Holladay, Mario Sweeney, Vu Tran. Web Services Presentation Web Services Theory James Holladay Tools – Visual Studio Vu Tran Tools – Net Beans Mario.
CSC8530 Distributed Systems XML Web Services David Vaglia.
Web Server Administration Web Services XML SOAP. Overview What are web services and what do they do? What is XML? What is SOAP? How are they all connected?
Lecture 15 Introduction to Web Services Web Service Applications.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Ez3950 SOAP & Z39.50 ZIG December 2000 at LC Poul Henrik Jørgensen, DBC
Accessing and Deploying Web Services Purpose: To build distributed Internet and Intranet applications using standards that allow other applications to.
Current Trends in Network- Based Application Developments Bill Chu Department of Software and Information Systems UNC Charlotte.
SOAP. Introduction SOAP is  a lightweight protocol  used for exchanging data in a decentralized distributed environment  XML-based  independent from.
SOAP & WSDL Aug’10 – Dec ’10. Introduction  SOAP - Simple Object Access protocol Protocol specification for exchanging structured information in the.
Web Services. ASP.NET Web Services  Goals of ASP.NET Web services:  To enable cross-platform, cross- business computing  Great for “service” based.
 Contains services or interfaces that can be accessed over Internet.  Provides certain functionalities and attributes for other applications.  Application.
1 EIE424 Distributed Systems and Networking Programming –Part II 3.1 SOAP – Introduction.
1 Web Services Web and Database Management System.
Enterprise Computing: Web Services
Simple Object Access Protocol. Web Services: SOAP2 Why Simple Object Access Protocol Light weight replacement for complicated distributed object technology.
XML and Web Services (II/2546)
CS603 Communication Mechanisms: SOAP 25 January 2002.
XML, XSL, and SOAP Building Object Systems from Documents CSC/ECE 591o Summer 2000.
S imple O bject A ccess P rotocol Karthikeyan Chandrasekaran & Nandakumar Padmanabhan.
Kemal Baykal Rasim Ismayilov
S O A P ‘the protocol formerly known as Simple Object Access Protocol’ Team Pluto Bonnie, Brandon, George, Hojun.
.NET and SOAP An Overview of SOAP By Raghavendra Aekka.
SOAP Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Transport Protocols  SOAP is used to send a message over any kind of transport protocol. Some of the protocols are, 1.HTTP 2.TCP/IP 3.UDP 4.SMTP.
ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP.
Web Services Part 1 -- Qinwei Zhu Part 2 – Yongqun He.
EGEE is a project funded by the European Union under contract IST SOAP Simple Object Access Protocol 3 – 4 June
Intro to Web Services Dr. John P. Abraham UTPA. What are Web Services? Applications execute across multiple computers on a network.  The machine on which.
Netprog: Soap & XML-RPC1 XML-RPC and SOAP. Netprog: Soap & XML-RPC2 XML Extensible Markup Language Markup Language. –HTML is also a markup language (but.
.NET Mobile Application Development XML Web Services.
Introduction to Web Services Presented by Sarath Chandra Dorbala.
Lecture VI: SOAP-based Web Service CS 4593 Cloud-Oriented Big Data and Software Engineering.
Net-centric Computing Web Services. Lecture Outline  What is Web Service  Web Service Architecture  Creating and using Java Web Services  Apache Axis.
Beginning 자바 웹 서비스 SOAP 강미란 Cyber-Infrastructure Research Lab Konkuk University.
SOAP, Web Service, WSDL Week 14 Web site:
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 9 Web Services: JAX-RPC,
Jim Fawcett CSE681 – SW Modeling & Analysis Spring 2005
Sabri Kızanlık Ural Emekçi
A Web Services Journey on the .NET Bus
INTRODUCTION TO WEB SERVICES CS 795. What is a Web Service ? Web service is a means by which computers talk to each other over the web using HTTP and.
Web Server Administration
Chapter 9 Web Services: JAX-RPC, WSDL, XML Schema, and SOAP
Presentation transcript:

Copyright 1999 – 2003 Ellis Horowitz SOAP 1 SOAP

Copyright 1999 – 2003 Ellis Horowitz SOAP 2 Simple Object Access Protocol Purpose of SOAP: to use the Internet to interact with remote applications –HTTP was not designed for the above purpose Usually done using Remote Procedure Calls (RPC), or Microsoft’s Distributed Component Object Model (DCOM), or the Internet Inter-Orb Protocol (IIOP) and others –These work well over LANs but over the Internet they have many problems

Copyright 1999 – 2003 Ellis Horowitz SOAP 3 The Trouble with Firewalls In the TCP/IP architecture, each protocol is assigned a unique port number, e.g. HTTP is 80 Most firewalls block traffic according to port number, but they often allow port 80 traffic to get through Distributed object protocols don’t have a single port assignment, they use dynamically assigned ports SOAP adds a distributed object protocol on top of the http protocol SOAP uses XML to define the format of request/response messages and then allows the HTTP POST command to send the info

Copyright 1999 – 2003 Ellis Horowitz SOAP 4 So, what is SOAP SOAP is a distributed object protocol which allows RPCs between clients and servers, and in addition manages to avoid firewalls, or A lightweight mechanism for exchanging structured and typed information between systems using XML It consists of three parts –The SOAP envelope for defining what is in a message, who should deal with it, and whether it is optional or mandatory –SOAP encoding rules for exchanging instances of application-defined datatypes –SOAP RPC defines a convention used to represent remote procedure calls and responses

Copyright 1999 – 2003 Ellis Horowitz SOAP 5 Example of SOAP Message in an HTTP Request A SOAP request is sent to StockQuote service with string parameter tickersymbol, returning a float XML namespaces are used to differentiate SOAP ids from application specific ids POST /StockQuote HTTP/1.1 Host: Content-Type: text/xml; charset="utf-8" Content-Length: nnnn SOAPAction: "Some-URI" DIS

Copyright 1999 – 2003 Ellis Horowitz SOAP 6 Example of SOAP Message in an HTTP Response HTTP/ OK Content-Type: text/xml; charset="utf-8" Content-Length: nnnn 34.5

Copyright 1999 – 2003 Ellis Horowitz SOAP 7 Message Exchanging in SOAP A SOAP application receiving a SOAP message must process it –Identify its parts –Verify that all mandatory parts are supported by the application –If there is a further destination, forward the message on All SOAP messages are encoded in XML SOAP defines two namespaces –The SOAP envelope has the namespace identifier –The SOAP serialization has the namespace identifier

Copyright 1999 – 2003 Ellis Horowitz SOAP 8 SOAP Messages have 3 Components A SOAP message is an XML document containing a mandatory SOAP envelope, an optional SOAP header and a mandatory SOAP body –The envelope is the top element of the XML document –The header is a generic way to add features to a SOAP message –The body is a container for mandatory information

Copyright 1999 – 2003 Ellis Horowitz SOAP 9 Simple Types SOAP uses all types defined by XML schemas Here is an example of a schema fragment and corresponding instance data Blue

Copyright 1999 – 2003 Ellis Horowitz SOAP 10 SOAP Template... Header information goes here Body information goes here Fault information goes here...

Copyright 1999 – 2003 Ellis Horowitz SOAP 11 The Envelope Element Must be the root element of a SOAP message Defines the XML document as a SOAP message Sets the namespace and encodingStyle... Message information goes here...

Copyright 1999 – 2003 Ellis Horowitz SOAP 12 Header Element Can contain additional application specific information about the SOAP message Example where the header contains info about the language and currency values en USD

Copyright 1999 – 2003 Ellis Horowitz SOAP 13 Body Element Must be present in a SOAP message Example Apples

Copyright 1999 – 2003 Ellis Horowitz SOAP 14 Fault Element Used to provide information about errors that occurred while processing the message Example Client Invalid Request

Copyright 1999 – 2003 Ellis Horowitz SOAP 15 SOAP Attributes Three optional attributes are: actor, encodingStyle and mustUnderstand Actor attribute defines the URL for which the header elements are intended Example en USD

Copyright 1999 – 2003 Ellis Horowitz SOAP 16 Encoding Style Attribute Used to define the format (data types) used in the document Example... Message information goes here...

Copyright 1999 – 2003 Ellis Horowitz SOAP 17 mustUnderstand Attribute Used to define if the receiver of a message must process a header element Example en USD

Copyright 1999 – 2003 Ellis Horowitz SOAP 18 SOAP Errors Error messages from SOAP applications are carried inside a Fault element. If present, it must appear as an element within the Body SOAP Fault elements have sub-elements Sub ElementDescription A code identifying the error The error as a string Who caused the error Specific error informationFault Codes ErrorDescription VersionMismatchInvalid namespace for the SOAP Envelope element MustUnderstandA child element of the Header element, with the mustUnderstand attribute set to "1", was not understood ClientThe message was incorrectly formed or contained incorrect information ServerThere was a problem with the server so the message could not proceed

Copyright 1999 – 2003 Ellis Horowitz SOAP 19 Stockquote Example with Mandatory Header POST /StockQuote HTTP/1.1 Host: Content-Type: text/xml; charset="utf-8" Content-Length: nnnn SOAPAction: "Some-URI" 5 DEF

Copyright 1999 – 2003 Ellis Horowitz SOAP 20 Stockquote Example but with multiple request parameters POST /StockQuote HTTP/1.1 Host: Content-Type: text/xml; charset="utf-8" Content-Length: nnnn SOAPAction: "Some-URI" DEF DEF Corp 34.1

Copyright 1999 – 2003 Ellis Horowitz SOAP 21 Similar Example but with a Mandatory Header HTTP/ OK Content-Type: text/xml; charset="utf-8" Content-Length: nnnn

Copyright 1999 – 2003 Ellis Horowitz SOAP 22 A SOAP Example Suppose Qwickbooks.com allows customers to place orders via SOAP, e.g. Boolean PlaceOrder([in] Title string, [in] Author String, [out] DaysToDelivery integer); Client invokes this method passing it a book title and author; the boolean result true means the order was successful A sample HTTP request would look like POST /BookServer HTTP/1.1 Host: to bookstore server Content-type: text/xml-SOAP#a new MIME type Content-Length: 160 MessageType: Call#indicates a function call #an instance of SerializedStream #name of method to invoke Harry Potter E.K. Rowling

Copyright 1999 – 2003 Ellis Horowitz SOAP 23 A SOAP Example II After the request is received and processed, a response is sent back HTTP/ OK Connection: close Content-type: text/xml-SOAP Content-Length: 177 MessageType: CallResponse 1 #method’s return value true 7

Copyright 1999 – 2003 Ellis Horowitz SOAP 24 Apache SOAP Requires a Web server that supports servlets and JavaServer Pages (JSPs). requires Apache Xerces (Java) version or higher, which supports the DOM (Document Object Model) level 2 that provides namespace support The HelloWorld service expects to obtain a person/user's name and returns a customized hello message to the caller. package hello; public class HelloServer { public String sayHelloTo(String name) { System.out.println("sayHelloTo(String name)"); return "Hello " + name + ", How are you doing?"; } }

Copyright 1999 – 2003 Ellis Horowitz SOAP 25 Supported Scalar Values Type valueTypeExample xsd:int32-bit signed integer-12 xsd:booleana boolean value, 1 or 01 xsd:stringstring of charactershello world xsd:float or xsd:doublesigned floating point number xsd:timeInstantdate/time T00:00:01-08:00 SOAP-ENC:base64base64- encoded binary eW91IGNhbid0IHJlYWQgdGhpcyE=

Copyright 1999 – 2003 Ellis Horowitz SOAP 26 Structs structs are specified by an XML element that contains sub-elements. Example The names of struct elements are significant, the order of the elements is not.

Copyright 1999 – 2003 Ellis Horowitz SOAP 27 Arrays specified by an XML element with a SOAP- ENC:arrayType attribute whose value begins with ur-type[, followed by the number of array elements, followed by ] Example 12 Egypt The order of array elements is significant, the names of the elements are not

Copyright 1999 – 2003 Ellis Horowitz SOAP 28 Fault Example HTTP/ Server Error Connection: close Content-Length: 511 Content-Type: text/xml; charset=utf-8 Date: Wed, 28 Mar :06:32 GMT Server: UserLand Frontier/7.0-WinNT

Copyright 1999 – 2003 Ellis Horowitz SOAP 29 Fault Example Continued SOAP-ENV:Client Can't call getStateName because there are too many parameters.

Copyright 1999 – 2003 Ellis Horowitz SOAP 30 Web Services Definition A web service is a piece of functionality exposed through a web interface and made accessible through standard internet protocols such as HTTP Web service messages are transmitted in XML format, defined by the Simple Object Access Protocol (SOAP)

Copyright 1999 – 2003 Ellis Horowitz SOAP 31 Web Services Features Web services allow a server to expose a set of functions that other computers can then call Platform and language independent (though not necessarily protocol-implementation independent) Location of client and server is irrelevant Firewall-friendly, since transmission occurs over the HTTP protocol, which is usually open for web servers anyway

Copyright 1999 – 2003 Ellis Horowitz SOAP 32 WSDL Document The Web Service Description Language document tells a server which functions are exposed to clients in a web service The WSDL document is an XML document that provides a client with all of the necessary information to invoke the web service offered by the server WSDL documents are very long and verbose WSDL documents can be written by a user, though Microsoft’s.NET framework provides a tool to automatically generate a WSDL document from a given web service (wsdl.exe)

Copyright 1999 – 2003 Ellis Horowitz SOAP 33 UDDI Universal Description, Discovery, and Integration is a registry that is intended to contain a repository of web services where users can search for a web service The search would return a DISCO document, which is an XML document that provides the location of the WSDL document for the given web service An example UDDI registry can be found at 3.ibm.com/services/uddi/findhttp://www- 3.ibm.com/services/uddi/find

Copyright 1999 – 2003 Ellis Horowitz SOAP 34 Platform Independence The platforms of the client and server are transparent (similar to browsing the web, where the client browser could be running Internet Explorer in Windows and the web server could be running Apache on Solaris)

Copyright 1999 – 2003 Ellis Horowitz SOAP 35 Language Independence The client and server applications can both be written in any language that is capable of packaging and parsing an XML document, and transmitting and receiving messages over a network Two languages widely used for this are C# and Java

Copyright 1999 – 2003 Ellis Horowitz SOAP 36 Protocol SOAP, as defined by W3C, is an XML-based lightweight protocol used for exchange of information in a decentralized, distributed environment SOAP messages are transmitted over the HTTP or HTTPS protocol (port 80 or port 443, respectively) SOAP is a special type of XML This implies that the messages generated and the protocol to transmit these messages are platform independent

Copyright 1999 – 2003 Ellis Horowitz SOAP 37 Protocol Implementation The format of the SOAP message that the web service will receive has not yet been standardized across implementations of the protocol W3C has developed a standard for SOAP messages, but the SOAP vendors (i.e. Microsoft, Apache, IBM) do not all implement the protocol exactly in compliance with the W3C specification This means that, at least for now, the web service protocol implementation must be known by a client calling the web service so that the SOAP message can be properly created

Copyright 1999 – 2003 Ellis Horowitz SOAP 38 Differences Microsoft and Apache have implemented SOAP slightly different, so a client that has created a message for a web service using Apache SOAP will have to be modified to call the same web service using Microsoft SOAP

Copyright 1999 – 2003 Ellis Horowitz SOAP 39 Microsoft SOAP Request POST /sort/sort.asmx HTTP/1.0 Content-Type: text/xml SOAPAction: User-Agent: Java1.2.2 Host: nunki.usc.edu:11069 Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Content-length: 552 <soap:Envelope xmlns:xsi=“ instance” xmlns:xsd=“ xmlns:soap=“

Copyright 1999 – 2003 Ellis Horowitz SOAP 40 Apache SOAP Request POST /soap/servlet/rpcrouter/ HTTP/1.0 Content-Type: text/xml SOAPAction: urn:sort User-Agent: Java1.2.2 Host: nunki.usc.edu:11069 Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Content-length: 798 <SOAP-ENV:Envelope xmlns:SOAP- ENV=“ xmlns:xsi=“ xmlns:xsd=“ <m:sort xmlns:m=“urn:sort” SOAP- ENV:encodingStyle=“ <numbers xmlns:ns=“ xsi:type=“ns:Array” ns:arrayType=“xsd:int[5]”>

Copyright 1999 – 2003 Ellis Horowitz SOAP 41 Microsoft SOAP Response HTTP/ OK Server: Microsoft-IIS/5.0 Date: Sun, 28 Apr :58:37 GMT Cache-Control: private, max-age=0 Content-Type: text/xml; charset=utf-8 Content-Length: 414 <sortResponse xmlns="

Copyright 1999 – 2003 Ellis Horowitz SOAP 42 Apache SOAP Response HTTP/ OK Content-Type: text/xml; charset=utf-8 Content-Length: 690 Date: Sun, 28 Apr :31:55 GMT Server: Apache Tomcat/4.0.3 (HTTP/1.1 Connector) Set-Cookie: JSESSIONID=4E68BC B5BFFD EF;Path=/soap <SOAP-ENV:Envelope xmlns:SOAP- ENV=“ xmlns:xsi=“ xmlns:xsd=“ <ns1:sortResponse xmlns:ns1=“urn:sort” SOAP- ENV:encodingStyle=“ <return xmlns:ns2=“ xsi:type=“ns2:Array” ns2:arrayType=“xsd:int[5]”>

Copyright 1999 – 2003 Ellis Horowitz SOAP 43 Microsoft vs. Apache MicrosoftApache Web Service Product.NET FrameworkTomcat Web Service Authoring Language Many, including C, C++, C#, Cobol, Visual Basic Java Creation/Deployment Tool GUI or Command LineCommand Line Platforms Supported Windows NT4.0, 2000 or higher only, though you may port to other platforms on your own Most Windows and Unix- based platforms

Copyright 1999 – 2003 Ellis Horowitz SOAP 44 Sort Example This example is focused more on the details of writing a web service and a client application, and less on the algorithm of the web service This web service, which has been written on a Windows 2000 platform using.NET and a Sun OS platform using Java, takes an array of integers and returns a sorted array

Copyright 1999 – 2003 Ellis Horowitz SOAP 45 Windows 2000 Web Service First, we need to write the code for the web service. Since we are writing this web service in Windows 2000, we will use C#, which is part of the.NET framework.NET allows a web service to be written in-line within an ASP.NET file (similar to an ASP file), which then allows for easy viewing of the WSDL document and an automatically generated test client accessible through a browser

Copyright 1999 – 2003 Ellis Horowitz SOAP 46 ASP.NET An ASP.NET file has a.asmx extension If you are writing a web service within an ASP.NET file, there is only one line of ASP code, and the rest is the web service, written in whatever.NET language specified in the ASP WebService tag To allow other people to use your web service, make this.asmx file available through your web server There is also no need to compile your web service -.NET will compile the service when necessary Note: To run.NET web services, you must have the.NET Framework SDK installed on the server You can download the.NET SDK from

Copyright 1999 – 2003 Ellis Horowitz SOAP 47 ASP.NET/C# Web Service using System; using System.Web; using System.Web.Services; [WebService(Namespace=" public class SortNumbers : System.Web.Services.WebService { [WebMethod(Description="Sorts a sequence of numbers in ascending orders")] public int[] sort(int [] numbers) { return sortNumbers(numbers); } private int[] sortNumbers(int [] numbers) { int temp; for (int i=0; i < numbers.Length; i++) { for (int j=0; j < i; j++) { if (numbers[i] < numbers[j]) { temp = numbers[i]; numbers[i] = numbers[j]; numbers[j] = temp; } } } return numbers; } }

Copyright 1999 – 2003 Ellis Horowitz SOAP 48 ASP.NET WebService Tag The ASP.NET WebService tag is used to specify the class name of the web service (required), the language in which the web service is written (optional, which defaults to C# if no language is given), and the CodeBehind attribute (optional, which specifies where web service code is located if it is in an external file)

Copyright 1999 – 2003 Ellis Horowitz SOAP 49 C# Web Service Code The C# code is similar to Java, but to make the class a web service, a few steps are required: 1.Any class that is to be a web service can be immediately preceded by a WebService attribute, which is used in WSDL generation to provide more information to the client application 2.Any method that is to be exposed in the web service must be public and be immediately preceded by a WebMethod attribute 3.No other methods in the class are exposed to the web service, but may be used in the accessible methods

Copyright 1999 – 2003 Ellis Horowitz SOAP 50 Web-Based Client If your client is web-based and you are not using a proxy class, the SOAP message returned will be displayed in the browser as a parsed XML document (for Internet Explorer version 5.5 and greater) Other browsers, such as Netscape, do not have built- in XML parsers, and therefore do not display the XML document parsed (or sometimes they throw error messages)

Copyright 1999 – 2003 Ellis Horowitz SOAP 51 Windows Client Application For the sort client, we wrote the client code to be accessed through a browser as a Java Server Page (JSP). This code could be running on any platform that supports JSPs, though it will connect to the Windows web service. Sun has a JSP IO tag library, which is used in this example to package the SOAP message that is traveling to the web service

Copyright 1999 – 2003 Ellis Horowitz SOAP 52 Windows Client Application Code

Copyright 1999 – 2003 Ellis Horowitz SOAP 53 Windows SOAP Request POST /sort/sort.asmx HTTP/1.0 Content-Type: text/xml SOAPAction: User-Agent: Java1.2.2 Host: nunki.usc.edu:11069 Accepts: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Content-length: 552 <soap:Envelope xmlns:xsi=“ xmlns:xsd=“ xmlns:soap=“

Copyright 1999 – 2003 Ellis Horowitz SOAP 54 Windows SOAP Response HTTP/ OK Server: Microsoft-IIS/5.0 Date: Sun, 28 Apr :58:37 GMT Cache-Control: private, max-age=0 Content-Type: text/xml; charset=utf-8 Content-Length: 414 <sortResponse xmlns="

Copyright 1999 – 2003 Ellis Horowitz SOAP 55 Sun OS Web Service The first step is to write the web service, which we will write in Java since we are running Tomcat4.0.3 on a Unix-based machine The code for the web service is not any different than any other class written in Java Compile the code after you have written the web service class

Copyright 1999 – 2003 Ellis Horowitz SOAP 56 Java Web Service public class sort { public int[] sort (int [] numbers) { int temp; for (int i=0; i < numbers.length; i++) { for (int j=0; j < i; j++) { if (numbers[i] < numbers[j]) { temp = numbers[i]; numbers[i] = numbers[j]; numbers[j] = temp; } } } return numbers; }

Copyright 1999 – 2003 Ellis Horowitz SOAP 57 Document Descriptor To deploy a web service using Tomcat, a document descriptor must be created, which is merely an XML document with a few required tags The id attribute of the service tag gives the name of the web service that is exposed to the client The methods attribute of the provider tag, which is a child of the service tag, gives the name of the methods that are exposed to the client The class attribute of the java tag, which is a child of the provider tag, gives the name of the class that is exposed to the client The mappings tag, which is a child of the service tag, provides mappings from Java objects to the equivalent SOAP objects if SOAP does not already know how to convert the data type All primitive Java data types, primitive arrays, and Strings are known by the Apache SOAP implementation

Copyright 1999 – 2003 Ellis Horowitz SOAP 58 Sort Document Descriptor org.apache.soap.server.DOMFaultListener

Copyright 1999 – 2003 Ellis Horowitz SOAP 59 Deploying the Web Service The ServiceManagerClient class, which is packaged with Tomcat 4.0.3, is used to deploy web services based on the document descriptor Assuming sort.xml is the name of the document descriptor for our web service, Tomcat is installed on port 8080 of nunki.usc.edu, and all of the jar files that came with Tomcat are in the system classpath, type the following command: java org.apache.soap.server.ServiceManagerClient deploy sort.xml It is then necessary to restart Tomcat before the new web service will be recognized

Copyright 1999 – 2003 Ellis Horowitz SOAP 60 Apache Client Application Code <% URL url = new URL(" Call call = new Call(); call.setTargetObjectURI("urn:sort"); call.setMethodName("sort1"); call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); Vector params = new Vector(); int [] array1 = {21, 65, 87, 78, 45}; params.addElement(new Parameter("numbers", int[].class, array1, Constants.NS_URI_SOAP_ENC)); call.setParams(params); Response resp = call.invoke(url, ""); if (resp.generatedFault()) { Fault fault = resp.getFault(); // generate fault information here } else { Parameter result = resp.getReturnValue(); result.setEncodingStyleURI(Constants.ATTR_ARRAY_TYPE); int [] sortedarray = (int[])result.getValue(); // contains sorted array %>

Copyright 1999 – 2003 Ellis Horowitz SOAP 61 Apache SOAP Request POST /soap/servlet/rpcrouter/ HTTP/1.0 Content-Type: text/xml SOAPAction: urn:sort User-Agent: Java1.2.2 Host: nunki.usc.edu:11069 Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Content-length: 798 <SOAP-ENV:Envelope xmlns:SOAP-ENV=“ xmlns:xsi=“ xmlns:xsd=“ <m:sort xmlns:m=“urn:sort” SOAP-ENV:encodingStyle=“ <numbers xmlns:ns=“ xsi:type=“ns:Array” ns:arrayType=“xsd:int[5]”>

Copyright 1999 – 2003 Ellis Horowitz SOAP 62 Apache SOAP Response HTTP/ OK Content-Type: text/xml; charset=utf-8 Content-Length: 690 Date: Sun, 28 Apr :31:55 GMT Server: Apache Tomcat/4.0.3 (HTTP/1.1 Connector) Set-Cookie: JSESSIONID=4E68BC B5BFFD EF;Path=/soap <SOAP-ENV:Envelope xmlns:SOAP- ENV=“ xmlns:xsi=“ xmlns:xsd=“ <ns1:sortResponse xmlns:ns1=“urn:sort” SOAP- ENV:encodingStyle=“ <return xmlns:ns2=“ xsi:type=“ns2:Array” ns2:arrayType=“xsd:int[5]”>

Copyright 1999 – 2003 Ellis Horowitz SOAP 63 Conclusion Web Services provide a new method of distributed computing Using standard protocols, the theory behind web services makes it appear as if a client does not need to concern itself with the platform running the web service Web services will most likely become the next paradigm for distributed computing, overcoming the platform dependency issues with RPC and COM