ICEC Tutorial Web Services

48
Web Services Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic

Transcript of ICEC Tutorial Web Services

Page 1: ICEC Tutorial Web Services

Web Services

Dr. Yuhong YanNRC-IIT-FrederictonInternet logic

Page 2: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Web Service Stack

Discovery UDDI

Transport HTTP, SMTP, FTP, BEEP

Description W SDL

XML messaging XML-RPC, SOAP, XML

Process BPEL4WS, WSCI, WS-CDL

Page 3: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Simple Object Access Protocol

Page 4: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

SOAP (Simple Object Access Protocol)

SOAP is a lightweight protocol for exchange of information in a decentralized, distributed environment.

� XML based protocol binds various internet protocols, like HTTP, SMTP, FTP, etc.

� Interoperability to Web Services

Page 5: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Why SOAP

� inter-application communication between systems written in arbitrary languages, across the Internet.

� An XML-based protocol for exchanging messages over Internet transport protocols, like HTTP, SMTP, FTP, etc.

� SOAP is platform-independent.

Page 6: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Inside SOAP

From Etban Cerami, “Web Services Essentials”, P53, figure 3-2

Envelope (required)

SOAP message

Header (optional)

Body (required)

Fault (optional)

Page 7: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Apache SOAP architecture

From Etban Cerami, “Web Services Essentials”, p69,. Fig 4-3

Service:HelloService.java

AXIS SOAP enginerpcrouter servlet

SOAP client: HelloClient.java

Jakarta Tomcat server

SOAP request:Service name: urn:HelloWorldMethod name: sayHelloParameter: firstName=“Yuhong”

lastName=“YanSOAP response:

Return value: “Yuhong Yan, welcome to SOAP”

“Yuhong Yan, Welcome to SOAP…”sayHello(“Yuhong”,”Yan)

12

3

4

5Http POST

Http GET

Page 8: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Anatomy of HelloWorld

� Server side code� Client side code� SOAP request� SOAP response

Page 9: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

HelloWorldService.java

package samples.HelloWorld;

public class HelloWorldService{

public String sayHello(String firstName, String lastName) throws Exception{

String aString = firstName + “ " + lastName + ", welcome to SOAP Web Service World!";

return aString;}

public String addString(String symbol, String dataType) throws Exception{

String aString = symbol + dataType;return aString;

}}

Page 10: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

TestClient

public class TestClient{

public static void main(String args[]){try{Options opts = new Options( args );args = opts.getRemainingArgs();

Service service = new Service();Call call = (Call) service.createCall();

Parse

arguments

Prepare to call

remote service

Page 11: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

TestClient.java (2)

call.setTargetEndpointAddress( new java.net.URL(opts.getURL()) );

if( args[0].equals("1") ) call.setOperationName( new QName("urn:HelloWorld", "sayHello"));

else

call.setOperationName( new QName("urn:HelloWorld", "addString"));

call.addParameter( “p1", XMLType.XSD_STRING,ParameterMode.IN );

call.addParameter( “p2", XMLType.XSD_STRING,ParameterMode.IN );

Set the URL of the

remote service

Service Name Service Method

Set the URL of the

remote service

Add Paras for

the remote

methods

Paras Name XML data typeIN/OUT/INOUT

Page 12: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

TestClient.java (3)

call.setReturnType( XMLType.XSD_STRING );

call.setUsername( opts.getUser() );call.setPassword( opts.getPassword() );

String res = (String) call.invoke( new Object[] { args[1], args[2] } );

System.out.println( "Return is: " + res );}catch( Exception e ){e.printStackTrace();

}}

}

Define the

return value

Security

options

Invoke

Service

Pass two paras

Page 13: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Request SOAP message

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope

xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body><ns1:sayHello

soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:HelloWorld">

<p1 xsi:type="xsd:string">Yuhong</p1><p2 xsi:type="xsd:string">Yan</p2></ns1:sayHello></soapenv:Body></soapenv:Envelope>

Remote method name

Name of the web service

Parameter name

Parameter type. need to match WSDL.

Value of the parameter

Page 14: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Response SOAP message

<soapenv:Envelopexmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body><ns1:sayHelloResponse

soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:HelloWorld"><ns1:sayHelloReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">

Yuhong,Yan, welcome to SOAP Web Service World!</ns1:sayHelloReturn>

</ns1:sayHelloResponse></soapenv:Body></soapenv:Envelope>

Page 15: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

SOAP Encoding

� Scalar Type: map to simple types in XML Schema<return xsi:type=“xsd:double" > 54.99 </return>

Page 16: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Primitives: the mapping table

xsd:base64Binary byte[]xsd:boolean booleanxsd:byte bytexsd:dateTime java.util.Calendarxsd:decimal java.math.BigDecimalxsd:double doublexsd:float floatxsd:hexBinary byte[]xsd:int intxsd:integer java.math.BigIntegerxsd:long longxsd:QName javax.xml.namespace.QNamexsd:short shortxsd:string java.lang.String

Page 17: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Compound Type

� Arrays: map to array in XML schema<return …>

<item xsi:type=“xsd:double" > 54.99 </item><item xsi:type=“xsd:double" > 19.99 </item>

</return>

� Structures: <return …><name xsi:type=“xsd:string"> Elia and Louis </name><price xsi:type=“xsd:double" > 19.99 </item></return>

Page 18: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

SOAP Extensions

� Authentication� Authorization� Reliability� Correlation� Transaction

Page 19: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Header (optional)

� For authentication, transaction management, and payment authorization

� Two defined attributes– Actor attribute: the chained node– MustUnderstand attribute: force the recipient to process

the element, if not understandable, return a fault

Page 20: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Header (optional) (2)

<SOAP-ENV:Header><ns1:PaymentAccount xmlns:ns1=“urn:ecerami” SOAP-ENV:mustUnderstand=“true”>

orsenigo473</ns1:PaymentAccount>

</SOAP-ENV:Header>

P54. the soapheader

Page 21: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Fault (optional)

� faultCode– SOAP-ENV:VersionMismatch– SOAP-ENV:MustUnderstand– SOAP-ENV:Client (non existing methods)– SOAP-ENV:Server (not able to access DB)

� faultString� faultActor� detail

Page 22: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Fault (optional)-2

<?xml version=‘1.0’ encoding=‘UTF-8’?><SOAP-ENV:Envelope

xmlns:SOAP-ENV=“ http://schemas.xmlsoap.org/soap/envelope/ ”xmlns:xsi=“ http://www.w3.org/1999/XMLSchema-instance ”xmlns:xsd=“ http://www.s3.org/1999/XMLSchema ”><SOAP-ENV:Body>

<SOAP-ENV:Fault><faultcode xsi:type=“xsd:string”>SOAP-ENV:Client</fa ultcode><faultstring xsi:type=“xsd:string”>

Failed to locate method (ValidateCreditCard) in cla ss(examplesCreditCard) at /usr/local/ActivePerl-5.6/l ib/site_perl/5.6.0/SOAP/Lite.pm line 1555.

</faultstring></SOAP-ENV:Fault>

</SOAP-ENV:Body></SOAP-ENV:Envelope>

P55. xml part (for faults)

Page 23: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Web Service Description Language

Page 24: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

WSDL:

� A contract between requestor and provider� Platform and language-independent� Describe SOAP services� Automatic tool to generate client and sever code

Page 25: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Interoperability Using WSDL

Get WSDL doc

Invoke Service

WSDL description

Client

URL

Service

SOAP

HTTP

Page 26: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

WSDL: Describe a web service

� Interface information describing all publicly available functions

� Data type information for all message requests and message responses

� Binding information about the transport protocol to be used

� Address information for locating the specified services

Page 27: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Structure of WSDL

From Etban Cerami, “Web Services Essentials”, P121 fig 6-1

<definitions>:Root WSDL Element

<types>: What data types will be transmitted?

<message>: What message will be transmitted?

<portType>: What operations (functions) will be supported?

<binding>: How will the messages be transmitted on the wire?What SOAP-specific details are there?

<service>: Where is the service located?Service Implementation Definition

Service Interface Definition

<port>: Where is the service located?

Page 28: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

An example of WSDL: HelloWorld

<wsdl:definitionstargetNamespace="http://localhost:8080/axis/services/urn:HelloWorld" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://localhost:8080/axis/services/urn:HelloWorld" xmlns:intf="http://localhost:8080/axis/services/urn:HelloWorld" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://www.w3.org/1999/XMLSchema" xmlns:tns2="http://www.w3.org/2003/05/soap-encoding" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

Page 29: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

<Service> : where the service is located

<wsdl:service name="HelloWorldServiceService"><wsdl:portbinding="impl:urn:HelloWorldSoapBinding" name="urn:HelloWorld">

<wsdlsoap:addresslocation="http://localhost:8080/axis/services/urn:HelloWorld" />

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

The service location: the endpoint of the

SOAP message

Page 30: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

<Binding>: bind messages to operations

<wsdl:binding name="urn:HelloWorldSoapBinding" type="impl:HelloWorldService">

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

- <wsdl:operation name="sayHello"><wsdlsoap:operation soapAction="" />

- <wsdl:input name="sayHelloRequest"><wsdlsoap:body

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://HelloWorld.samples" use="encoded" />

</wsdl:input>- <wsdl:output name="sayHelloResponse"><wsdlsoap:body

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost:8080/axis/services/urn:HelloWorld" use="encoded" />

</wsdl:output></wsdl:operation>

- </wsdl:binding>

Use SOAP HTTP protocol

Page 31: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

<portType> : operations supported

<wsdl:portType name="HelloWorldService">- <wsdl:operation name="sayHello"

parameterOrder="in0 in1"><wsdl:input message="impl:sayHelloRequest" name="sayHelloRequest" />

<wsdl:outputmessage="impl:sayHelloResponse" name="sayHelloResponse" />

</wsdl:operation></wsdl:portType>

Input Message

Output Message

Page 32: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

<message>: define content of message

<wsdl:message name="sayHelloRequest"><wsdl:part name="in0" type="tns2:string" /> <wsdl:part name="in1" type="tns2:string" /> </wsdl:message>

<wsdl:message name="sayHelloResponse"><wsdl:part name="sayHelloReturn" type="tns2:string" />

</wsdl:message>

Page 33: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

– Dynamic invocation interface (DII) (bottom right).

� No stubs/ties; WSDL not necessary.� More coding� Flexible.

– Using static stubs (top right).� Tool creates stubs and ties c.f. RMI;

client operates on proxy (stub).� Less code than DII.

– Dynamic proxy.� No stubs, client creates proxy class

at runtime from WSDL.� More portable than static stubs.

Client app.Service implementation

Axis/JAX-RPCruntime

Axis/JAX-RPCruntime

SOAP messagesHTTP transport

Three Ways for Client to Invoke a Service

Client app.

Stubs

Axis/JAX-RPCruntime

Service implementation

Skeleton

Axis/JAX-RPCruntime

SOAP messagesHTTP transport

Client app.

Stubs

Axis/JAX-RPCruntime

Page 34: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Stub-Skeleton Architecture

Transport

Protocol (SOAP)

Server Side JAX-RPC

Runtime System

JAX-RPC API JAX-RPC API

Client Side JAX-RPC

Runtime System

Stub

Service Endpoint

WSDL description

WSDL<->Java Mapping

Service Client

Dispatch

Skeleton

Page 35: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

WSDL2Java

A service implementation (the locator)

A service interfaceFor each service

A stub classFor each binding

A java interfaceFor each portType

A holder if this type is used as an inout/out parameter

A java classFor each entry in

the type section

Java class(es) generatedWSDL clause

Page 36: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Many (C++, Java, VB, etc.)

Any (with IDL mapping standards)

javaAny (with XML parser, SOAP composition)

Compliant prog. Langs.

MS IDLIDL(primitive and structure)

Primitive,Serialized objects

XML schema (allow customized data type)

Data Binding

ORPCIIOPJRMPHttpTransportProtocol

DCOMCORBARMIWeb Service

Web Services vs. Middlewares

Page 37: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Client: proxyServer: stub

Client: stub or proxyServer: skeleton

Client: stub or proxyServer: skeleton

StubProxyDII

Routine

Get Pointer of server objects

Get reference of server object

Get references of server objects

By SOAP message

Remote Call

MS IDLIDLInterface of server objects

WSDLInterface Description

DCOMCORBARMIWeb Services

Page 38: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Web Service Discovery

Page 39: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Three Approaches

� The registry approach� The index approach� The peer-to-peer approach

Page 40: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

UDDI: Universal Description, Discovery, and Integration

� White pages � Yellow pages� Green pages

Page 41: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

White pages

� Information on a business itself– Locations of the business– Contact names– Unique identifiers, e.g. tax IDs– URL

� Associated with <businessEntity> element

Page 42: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Yellow pages

� Categorized information about the servicesprovided by a business.

� Categorization: assigning one or more taxonomies to the business– E.g. a service is categorized as an “online store” and as

an “Music Store”

� Associated with <businessService> element

Page 43: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Green pages

� Technical information about a service which is offered by a business.– Service location (URL)– Category– Specification of the service

� Associated with <businessService> and <bindingTemplate> elements

Page 44: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Web Service vs. ebXML

Page 45: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Implementation phase of ebXML

Page 46: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

Runtime phase in ebXML

Company A Company B

ebXML Registry

look up CPP of

Company A

download CPP

create and send CPA

conduct business

transactions

1

2

3

4

Page 47: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

SOAP in ebXML

SOAP structure for Web Service

SOAP structure for ebXML

Page 48: ICEC Tutorial Web Services

13-Aug-06ICEC 2006 Tutorial on SOA

ebXML components

� Business documents:– Core components

� Business transactions� Trade partner agreements

– CPP– CAP

� Business registration