49
Web Services Web Services Overview Overview Inspired by slides written by Inspired by slides written by Marlon Pierce Marlon Pierce Community Grids Lab Community Grids Lab Indiana University Indiana University

Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Embed Size (px)

Citation preview

Page 1: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Web Services OverviewWeb Services Overview

Inspired by slides written byInspired by slides written byMarlon PierceMarlon Pierce

Community Grids LabCommunity Grids LabIndiana UniversityIndiana University

Page 2: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

What Are Web Services?What Are Web Services?

The The Web services Web services framework is an framework is an XMLXML-based distributed -based distributed object/service/component system.object/service/component system.

• Intended to support Intended to support machine-to-machinemachine-to-machine interactions over the interactions over the network.network.

The basic idea is to build a platform and programming The basic idea is to build a platform and programming language-independent language-independent distributed invocation system distributed invocation system out of out of existing existing Web standardsWeb standards..

Very loosely defined, when compared to Very loosely defined, when compared to CORBACORBA, etc., etc.

Inherits both good and bad of the WebInherits both good and bad of the Web

• Scalable, simple, distributedScalable, simple, distributed

• But no centralized management: must be tolerant of failures.But no centralized management: must be tolerant of failures.

Page 3: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Basic ArchitecturesBasic Architectures

Browser

WebServer

HTTP GET/POST

DB

JDBC

WebServer

DB

JDBC

Browser

WebServer

SOAP

GUIClient

SOAPWSDL

WSDL

WSD

LWSD

L

HTTPHTTP Web ServicesWeb Services

Page 4: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Explanation of Previous SlideExplanation of Previous Slide

The diagram on the left represents a standard The diagram on the left represents a standard web application.web application.• Browsers converse with web servers using HTTP Browsers converse with web servers using HTTP

GET/POST methods.GET/POST methods.

• Servlets or CGI scripts process the parameters and take Servlets or CGI scripts process the parameters and take action (for example, connection to a DB).action (for example, connection to a DB).

• Examples: Examples: Google, AmazonGoogle, Amazon

On the right, we have a Web services system.On the right, we have a Web services system.• Interactions may be either through the browser or Interactions may be either through the browser or

through a desktop client (in Java, Python, etc.)through a desktop client (in Java, Python, etc.)

• Examples: Examples: Google, Amazon Google, Amazon (again !!!)(again !!!)

Page 5: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

SOAP e WSDLSOAP e WSDL

SOAPSOAP: Simple Object Access Protocol: Simple Object Access Protocol• XML Message format between client and XML Message format between client and

service.service.

WSDLWSDL: Web Service Description Language.: Web Service Description Language.• Describes how the service is to be usedDescribes how the service is to be used

• Similar to Java Interface.Similar to Java Interface.

• Guideline for constructing SOAP messages.Guideline for constructing SOAP messages.

• WSDL is an XML language for writing WSDL is an XML language for writing Application Programmer InterfacesApplication Programmer Interfaces (APIs). (APIs).

Page 6: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Amazon and Google Experiment Amazon and Google Experiment with Web Serviceswith Web Services

Both Google and Amazon offer Web Both Google and Amazon offer Web services.services.

Why? To allow partners to develop custom Why? To allow partners to develop custom user interfaces and applications that use user interfaces and applications that use Google and Amazon data and services.Google and Amazon data and services.

You can download their APIs and try them.You can download their APIs and try them.• http://www.google.com/apis/

• http://www.amazon.com/webservices

Page 7: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Why Use Web Services?Why Use Web Services?

Web services provide a clean Web services provide a clean separationseparation between a functionality and its user between a functionality and its user interface.interface.

This allows a company (Google) with a This allows a company (Google) with a sophisticated functionality and huge sophisticated functionality and huge amounts of data to make that functionality amounts of data to make that functionality available to its partners.available to its partners.• ““Don’t worry about how Don’t worry about how PageRankPageRank works or works or

web robots or data storage. We will do that. web robots or data storage. We will do that. You just use this WSDL API to build your client You just use this WSDL API to build your client application and use our search engine.”application and use our search engine.”

Page 8: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Google’s PageRankGoogle’s PageRank

Google’s Google’s PageRankPageRank is a search engine that was is a search engine that was developed by two Stanford students.developed by two Stanford students.

It is anIt is an open open algorithm published in scholarly algorithm published in scholarly journals, conferences.journals, conferences.

• Previous search engines were all proprietary.Previous search engines were all proprietary.

Page 9: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

When to Use Web Services?When to Use Web Services?

Two or more organizations need to Two or more organizations need to cooperatecooperate• One needs to write an application that uses another’s One needs to write an application that uses another’s

service.service.

Services can be Services can be upgraded independentlyupgraded independently of of clients.clients.• Google can improve PageRank implemenation without Google can improve PageRank implemenation without

telling me.telling me.

• Just don’t change the WSDL. Just don’t change the WSDL.

Services can be easily expressed with simple Services can be easily expressed with simple request/response request/response semantics and simple semantics and simple statestate..

Page 10: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

XML and Web servicesXML and Web services

XMLXML provides a natural substrate for distributed provides a natural substrate for distributed computing:computing:• It’s just a data description.It’s just a data description.• Independent from platform and programming language.Independent from platform and programming language.

So let’s describe the pieces.So let’s describe the pieces. Web Services Description Language (WSDL)Web Services Description Language (WSDL)

• Describes how to invoke a service.Describes how to invoke a service.• Can bind to SOAP for actual invocation.Can bind to SOAP for actual invocation.

Simple Object Access Protocol (SOAP)Simple Object Access Protocol (SOAP)• Wire protocol extension for conveying Remote Wire protocol extension for conveying Remote

Procedure Calls (RPC).Procedure Calls (RPC).• Can be carried over HTTP or SMTP.Can be carried over HTTP or SMTP.

Page 11: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Before Going On…Before Going On…

In the next several slides we’ll go into the details In the next several slides we’ll go into the details of WSDL and SOAP.of WSDL and SOAP.

But in practice, But in practice, you don’t need to work directly you don’t need to work directly with eitherwith either..

• Most tools generate the WSDL for you from your Java Most tools generate the WSDL for you from your Java class.class.

• SOAP messages are constructed by classes.SOAP messages are constructed by classes.

• Generated Generated client stubsclient stubs will even hide SOAP classes will even hide SOAP classes behind a local behind a local proxyproxy that looks like a local class but that looks like a local class but actually constructs SOAP calls to the remote server.actually constructs SOAP calls to the remote server.

Page 12: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Web Services Web Services Description LanguageDescription Language

Defines what your service Defines what your service does and how it is invokeddoes and how it is invoked

Page 13: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

WSDL OverviewWSDL Overview

WSDL is an XML-based Interface Definition Language.WSDL is an XML-based Interface Definition Language.

• You can define the APIs for all of your services in WSDL.You can define the APIs for all of your services in WSDL.

WSDL docs are broken into five major parts:WSDL docs are broken into five major parts:

• Data definitionsData definitions (in XML) for custom types (in XML) for custom types

• Abstract message definitionsAbstract message definitions (request, response)(request, response)

• Organization of messages into “Organization of messages into “portTypesportTypes” and “” and “operationsoperations” ” (which correspond to classes and methods). (which correspond to classes and methods).

• Protocol bindingsProtocol bindings (to SOAP, for example)(to SOAP, for example)

• Service point locationsService point locations (URLs)(URLs)

Some interesting featuresSome interesting features

• A single WSDL document can describe several versions of an A single WSDL document can describe several versions of an interface.interface.

• A single WSDL doc can describe several services.A single WSDL doc can describe several services.

Page 14: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

The Java CodeThe Java Code

public public String[] execLocalCommand(String command)String[] execLocalCommand(String command) { {

Runtime rt = Runtime.getRuntime();Runtime rt = Runtime.getRuntime();

String stdout="",stderr=""; String stdout="",stderr="";

try {try {

Process p = Process p = rt.exec(command)rt.exec(command);;

BufferedReader in=BufferedReader in=

new BufferedReader(new new BufferedReader(new InputStreamReader(p.getInputStream()));InputStreamReader(p.getInputStream()));

BufferedReader err= BufferedReader err=

new BufferedReader(new new BufferedReader(new InputStreamReader(p.getErrorStream()));InputStreamReader(p.getErrorStream()));

Page 15: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Java Code ContinuedJava Code Continued

String line;String line;

while((line=in.readLine())!= null) while((line=in.readLine())!= null) {stdout+=line+"\n";}{stdout+=line+"\n";}

in.close();in.close();

while ((line=err.readLine())!=null) while ((line=err.readLine())!=null) {stderr+=line+"\n";}{stderr+=line+"\n";}

err.close();err.close();

}//End of try{}}//End of try{}

catch (Exception eio) {…}catch (Exception eio) {…}

String[] retstring=new String[2];String[] retstring=new String[2];

retstring[0]=stdout;retstring[0]=stdout;

retstring[1]=stderr;retstring[1]=stderr;

return retstring;return retstring;

} //End of method} //End of method

Page 16: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

WSDL Example: Job SubmissionWSDL Example: Job Submission

Our example is a simple service that can execute Our example is a simple service that can execute remote commands (remote commands (locallocal on the server). on the server).

Service implementation (in Java) has a single Service implementation (in Java) has a single methodmethod

• ExecLocalExecLocal takes a single string argument (the takes a single string argument (the command to be executed) command to be executed)

• returns a string array (with standard out and error).returns a string array (with standard out and error).

In this case the WSDL interface is mapped to a In this case the WSDL interface is mapped to a Java interface.Java interface.

Page 17: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

The Full WSDLThe Full WSDL

The following slide contains the WSDL The following slide contains the WSDL definition for the Job Submit service.definition for the Job Submit service.

• Some data definitions are omitted.Some data definitions are omitted.

As you can see, WSDL is very As you can see, WSDL is very verboseverbose

• Typically, you don’t write WSDLTypically, you don’t write WSDL

• The WSDL file is generated from the Java class The WSDL file is generated from the Java class by by Apache AxisApache Axis..

We will go through the parts of the doc in We will go through the parts of the doc in some detail.some detail.

Page 18: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions> … </wsdl:definitions><wsdl:message name="execLocalCommandResponse"> …<wsdl:message name="execLocalCommandRequest"> …<wsdl:portType name="SJwsImp"> <wsdl:operation name="execLocalCommand"> <wsdl:input message="impl:execLocalCommandRequest" name="execLocalCommandRequest"/> <wsdl:output message="impl:execLocalCommandResponse" name="execLocalCommandResponse"/> </wsdl:operation></wsdl:portType><wsdl:binding name="SubmitjobSoapBinding" type="impl:SJwsImp"> <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name=“execLocalCommand"> <wsdlsoap:operation soapAction=""/> <wsdl:input name=“impl:execLocalCommandRequest"> <wsdl:output name="impl:execLocalCommandResponse"> </wsdl:operation></wsdl:binding><wsdl:service name="SJwsImpService"> <wsdl:port binding="impl:SubmitjobSoapBinding" name="Submitjob"></wsdl:service></wsdl:definitions>

Page 19: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

WSDL Elements: Types, MessagesWSDL Elements: Types, Messages

TypesTypes: describes custom XML data types used in : describes custom XML data types used in messages (optional).messages (optional).• We’ll see an example for defining arrays.We’ll see an example for defining arrays.

MessageMessage: abstractly defines the messages that : abstractly defines the messages that need to be exchanged.need to be exchanged.• Each method/function in the interface contains 0-1 Each method/function in the interface contains 0-1

request and 0-1 response messages.request and 0-1 response messages.

• Each message consists of Each message consists of partpart elements. Usually you elements. Usually you need one part for each variable sent or received. Parts need one part for each variable sent or received. Parts can either be XML primitive types or custom complex can either be XML primitive types or custom complex types.types.

Page 20: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Types for Job SubmissionTypes for Job Submission

The job submission service receives a string (the The job submission service receives a string (the command) and returns a 2-elements array.command) and returns a 2-elements array.

StringsStrings are XML Schema are XML Schema primitive typesprimitive types, so we don’t , so we don’t need a special definition in our WSDL.need a special definition in our WSDL.

ArraysArrays are are not primitive typesnot primitive types. They are defined in . They are defined in the the SOAP encoding SOAP encoding schema, so we will import the schema, so we will import the definition of this XML schema.definition of this XML schema.

• In other words, SOAP has rules for array In other words, SOAP has rules for array encoding; simple XML has not.encoding; simple XML has not.

Page 21: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

WSDL types for Custom Data DefinitionWSDL types for Custom Data Definition<wsdl:definitions><wsdl:types><schema

targetNamespace="http://.../GCWS/services/Submitjob" xmlns:impl="http://.../GCWS/services/Submitjob" xmlns="http://www.w3.org/2001/XMLSchema"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:wsdl="http://schemas.xmlsoap.org/wsdl"xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"

> <import namespace="http://schemas.xmlsoap.org/soap/encoding/" /> <complexType name="Array_of_string"> <complexContent> <restriction base="soapenc:Array"> <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]" /> </restriction> </complexContent> </complexType></schema></wsdl:types></wsdl:definitions>

Page 22: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

We start with some useful namespace definitions.We start with some useful namespace definitions.

We next import the We next import the soap encodingsoap encoding schema schema

• It has the array definitions we need.It has the array definitions we need.

• importimport means a simple cut-and-paste of the entire means a simple cut-and-paste of the entire soap soap encoding encoding XML schema.XML schema.

Finally, we define our own local XML complex type, Finally, we define our own local XML complex type, Array_of_stringArray_of_string..

• This extends the SOAP array typeThis extends the SOAP array type

• We We restrict restrict this to String arraysthis to String arrays

Inserting a TypeInserting a Type

Page 23: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Message ElementsMessage Elements

Our service implementation has one method:Our service implementation has one method:

public String[] execLocalCommand(String cmd)public String[] execLocalCommand(String cmd)

This will require one “request” message and one This will require one “request” message and one “response” message.“response” message.

Each message has one Each message has one partpart::

• RequestRequest message must send the String cmd. message must send the String cmd.

• ResponseResponse must get back the String[] array (defined previously must get back the String[] array (defined previously as a custom type).as a custom type).

If we had to pass two input variables, our “request” If we had to pass two input variables, our “request” message would need two part elements.message would need two part elements.

Note: the Note: the namename attributes of messages are important, attributes of messages are important, because they are referred later!because they are referred later!

Page 24: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Message Examples for Job Message Examples for Job Submission ServiceSubmission Service

<wsdl:message name="execLocalCommandRequest">

  <wsdl:part type="xsd:string" />

</wsdl:message><wsdl:message

name="execLocalCommandResponse">  <wsdl:part type="impl:Array_of_string" /> </wsdl:message>

Page 25: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

portTypesportTypes

portTypeportType elements map messages to elements map messages to operationsoperations.. You can think ofYou can think of

• portType==classportType==class

• operation==methodoperation==method

Operations can contain input, output, and fault bindings for Operations can contain input, output, and fault bindings for messages.messages.

An operation may support one of the following message An operation may support one of the following message styles:styles:• One-wayOne-way: request only: request only

• Two-wayTwo-way: request/response: request/response

• Solicit-responseSolicit-response: server “push” and client response: server “push” and client response

• NotificationNotification: one-way server push: one-way server push

Page 26: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

portType for JobSubmitportType for JobSubmit

We previously defined the messages and types We previously defined the messages and types needed. Now we bind them into the portType needed. Now we bind them into the portType structure.structure.

PortType names are importantPortType names are important

• They will be referenced by They will be referenced by bindingbinding element.element.

Note: names of previously defined messages are Note: names of previously defined messages are used as references in the operations.used as references in the operations.

Page 27: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

<wsdl:portType name="SJwsImp"> <wsdl:operation name="execLocalCommand"> <wsdl:input message="impl:execLocalCommandRequest" name="execLocalCommandRequest" />  <wsdl:output message="impl:execLocalCommandResponse"

name="execLocalCommandResponse" /> </wsdl:operation></wsdl:portType>

portType definitionportType definition

Page 28: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Some Notes on the PortType DefinitionSome Notes on the PortType Definition

PortTypes refer to messages by namePortTypes refer to messages by name

• The The messagemessage attributes in <input> and attributes in <input> and <output> elements of <operation> refer to <output> elements of <operation> refer to the the namename attributes of the previously defined attributes of the previously defined messages.messages.

• The operation and portType names will The operation and portType names will similarly be used for reference in forthcoming similarly be used for reference in forthcoming tags.tags.

Page 29: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

PortType BindingsPortType Bindings

portTypes are abstract interface definitions.portTypes are abstract interface definitions.

• portTypes don’t say anything about how to invoke a remote portTypes don’t say anything about how to invoke a remote method.method.

Remote invocations are defined in Remote invocations are defined in bindingbinding elements.elements.

WSDL specification provides different types of bindings:WSDL specification provides different types of bindings:

• SOAP SOAP (default)(default)

• HTTPHTTP

• MIMEMIME (e-mail) (e-mail)

Page 30: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

SOAP Bindings for JobSubmit ServiceSOAP Bindings for JobSubmit Service

Note that the binding element contains a mixture of tags Note that the binding element contains a mixture of tags from different namespaces (wsdl and wsdlsoap).from different namespaces (wsdl and wsdlsoap).

WSDL child elements for WSDL child elements for bindingbinding element are element are operation, operation, input, input, and and output.output.

WSDLSOAP elements give instructions to map WSDL to the WSDLSOAP elements give instructions to map WSDL to the protocol of choice (SOAP in this case).protocol of choice (SOAP in this case).

The The bindingbinding element name is important, it will be used as element name is important, it will be used as a reference by a reference by portport definitions. definitions.

Page 31: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

<wsdl:binding name="SubmitjobSoapBinding" type="impl:SJwsImp">

<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />

<wsdl:operation name="execLocalCommand"> <wsdl:input name="execLocalCommandRequest">  <wsdlsoap:body

encodingStyle=http://schemas.xmlsoap.org/soap/encoding/ namespace="http://.../GCWS/services/Submitjob" use="encoded" />

  </wsdl:input> <wsdl:output name="execLocalCommandResponse">  <wsdlsoap:body encodingStyle=http://schemas.xmlsoap.org/soap/encoding/ namespace=http://.../GCWS/services/Submitjob

use="encoded" />   </wsdl:output>    </wsdl:operation>  </wsdl:binding>

Page 32: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

A Closer Look at SOAP BindingA Closer Look at SOAP Binding

<wsdlsoap:body <wsdlsoap:body encodingStyle=http://schemas.xmlsoap.org/soap/encoding/ encodingStyle=http://schemas.xmlsoap.org/soap/encoding/ namespace=http://.../GCWS/services/Submitjob namespace=http://.../GCWS/services/Submitjob use="encoded"/>use="encoded"/>

All this really means is “encode the message with All this really means is “encode the message with the rules in encodingStyle and put it in the SOAP the rules in encodingStyle and put it in the SOAP body.”body.”

The bindings are just instructions that must be The bindings are just instructions that must be implemented by the SOAP message generator.implemented by the SOAP message generator.

Page 33: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Service and Port DefinitionsService and Port Definitions

We have defined the class interfaces We have defined the class interfaces (portTypes) and the rules for binding to a (portTypes) and the rules for binding to a particular protocol.particular protocol.

portport elements define how the bindings elements define how the bindings (and thus the portTypes) are associated (and thus the portTypes) are associated with a particular server.with a particular server.

The The serviceservice element collects element collects portsports..

Page 34: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

<wsdl:service name="SJwsImpService"> <wsdl:port

binding="impl:SubmitjobSoapBinding" name="Submitjob">

  <wsdlsoap:address location="http://.../GCWS/services/Submitjob" />

  </wsdl:port></wsdl:service>

Service and Port Elements for the Service and Port Elements for the Job Submission ServiceJob Submission Service

Page 35: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

ExplanationExplanation

Note that the port element’s binding attribute Note that the port element’s binding attribute points to the appropriate points to the appropriate bindingbinding element by element by name.name.

The only purpose of the port element is to point The only purpose of the port element is to point to a to a service locationservice location (a URL). (a URL).

Ports are child elements of the Ports are child elements of the service service element. element. A service can contain one or more ports.A service can contain one or more ports.

• a single portType may correspond to several ports, each a single portType may correspond to several ports, each with a different protocol binding and service address.with a different protocol binding and service address.

Page 36: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Simple Object Access Simple Object Access ProtocolProtocol

A message format for A message format for exchanging structured, typed exchanging structured, typed

informationinformation

Page 37: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

SOAP BasicsSOAP Basics

SOAP is a format of XML messages for SOAP is a format of XML messages for exchanging structured, typed data. exchanging structured, typed data.

SOAP is not a transport protocol. You must attach SOAP is not a transport protocol. You must attach your message to a transport mechanism like your message to a transport mechanism like HTTP.HTTP.

Page 38: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

SOAP StructureSOAP Structure

A SOAP message is contained in an A SOAP message is contained in an envelopenvelop..

The envelop element in turn contains (in order)The envelop element in turn contains (in order)

• An optional An optional headerheader with one or more entrieswith one or more entries. .

• A A bodybody element that contains the XML element that contains the XML messages.messages.

Page 39: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

SOAP HeadersSOAP Headers

Headers are really just extension points where Headers are really just extension points where you can include elements from other you can include elements from other namespaces.namespaces.

• i.e., headers can contain arbitrary XML.i.e., headers can contain arbitrary XML.

Header entries may optionally have a Header entries may optionally have a mustUnderstandmustUnderstand attribute. attribute.

• mustUnderstand=1 means the message recipient must mustUnderstand=1 means the message recipient must process the header element.process the header element.

• If mustUnderstand=0 or is missing, the header element If mustUnderstand=0 or is missing, the header element is optional.is optional.

Page 40: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

SOAP BodySOAP Body

The body contains the XML message that you are The body contains the XML message that you are transmitting.transmitting.

The message format is not specified by SOAP.The message format is not specified by SOAP.

• The <Body></Body> tag pairs are just a way to notify The <Body></Body> tag pairs are just a way to notify the recipient that the actual XML message is contained the recipient that the actual XML message is contained there.there.

• The recipient decides what to do with the message.The recipient decides what to do with the message.

Page 41: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Developing Web Developing Web ServicesServices

Using Apache Axis to develop Java Using Apache Axis to develop Java implementations of Web services.implementations of Web services.

Page 42: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Web Service Development ToolsWeb Service Development Tools

Web service toolkits exist for various Web service toolkits exist for various programming languages:programming languages:

• C++,Python, Perl, Microsoft .NETC++,Python, Perl, Microsoft .NET

We’ll concentrate on building We’ll concentrate on building JavaJava Web services Web services with with Apache AxisApache Axis..

Page 43: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Apache Axis OverviewApache Axis Overview

Apache Axis is a toolkit for converting Java Apache Axis is a toolkit for converting Java applications into Web services.applications into Web services.

Axis service deployment tools allow you to Axis service deployment tools allow you to publish your service in a particular application publish your service in a particular application server (server (TomcatTomcat).).

Client sideClient side: Axis client tools allow you to convert : Axis client tools allow you to convert WSDL into client “stubs” (or “proxies”).WSDL into client “stubs” (or “proxies”).

Server sideServer side: Axis runtime tools accept incoming : Axis runtime tools accept incoming SOAP requests and redirect them to the SOAP requests and redirect them to the appropriate service.appropriate service.

Page 44: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Developing and Deploying a ServiceDeveloping and Deploying a Service

Download and install Download and install TomcatTomcat and and AxisAxis.. Write a Java implementationWrite a Java implementation

• Our SubmitJob is a simple example.Our SubmitJob is a simple example.

• Compile it with Tomcat.Compile it with Tomcat. Write a deployment descriptor (Write a deployment descriptor (WSDDWSDD) for your service.) for your service.

• It will be used by Axis runtime to direct SOAP calls.It will be used by Axis runtime to direct SOAP calls. Use Axis tools to install your WSDD file.Use Axis tools to install your WSDD file.

• It tells the axis servlet to load your class and direct SOAP It tells the axis servlet to load your class and direct SOAP requests to it.requests to it.

That’s it.That’s it.• Axis will automatically generate the WSDL for your service.Axis will automatically generate the WSDL for your service.

Page 45: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

<deployment name="Submitjob"

xmlns="http://xml.apache.org/axis/wsdd/"

xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<service name="Submitjob" provider="java:RPC">

<parameter name="scope" value="request"/>

<parameter name="className"

value="WebFlowSoap.SJwsImp"/>

<parameter name="allowedMethods"

value="execLocalCommand"/>

</service>

</deployment>

Sample WSDDSample WSDD

Page 46: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

EffectEffect

Axis will create a service calledAxis will create a service called• http://your.server/services/SubmitJobhttp://your.server/services/SubmitJob

WSDL for service is available fromWSDL for service is available from

• http://your.server/services/SubmitJob?wsdlhttp://your.server/services/SubmitJob?wsdl A list of all services is available fromA list of all services is available from

• http://your.server/serviceshttp://your.server/services

Page 47: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

WSDL generatedstarting from the Java

implementation.

Page 48: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Building a Client with AxisBuilding a Client with Axis

Obtain the WSDL file.Obtain the WSDL file. Generate client stubs Generate client stubs

• Stubs look like local objectsStubs look like local objects

• They convert method invocations into SOAP messages.They convert method invocations into SOAP messages.

Write a client application with the stubsWrite a client application with the stubs• Can be a Java GUI, a JSP page, etc.Can be a Java GUI, a JSP page, etc.

Compile everything and run.Compile everything and run.

Page 49: Web Services Overview Inspired by slides written by Marlon Pierce Community Grids Lab Indiana University

Sample Java Client Code Sample Java Client Code

/**Create SubmitJob client object and point to the service you want to /**Create SubmitJob client object and point to the service you want to use */ use */

SubmiJob sjws = new SubmiJob sjws = new

SubmitJobServiceLocator().getSubmitjob(newSubmitJobServiceLocator().getSubmitjob(new

URL(http://your.server/services/SubmitJob));URL(http://your.server/services/SubmitJob));

/** Invoke the method as if local. *//** Invoke the method as if local. */

String[] messages =String[] messages =

sjws.execLocalCommand(command);sjws.execLocalCommand(command);