• No results found

Web-Service Example. Service Oriented Architecture

N/A
N/A
Protected

Academic year: 2021

Share "Web-Service Example. Service Oriented Architecture"

Copied!
13
0
0

Loading.... (view fulltext now)

Full text

(1)

Web-Service Example

(2)

Fundamentals

Roles

– Service provider

– Service Consumer

– Registry

Operations

– Publish (by provider)

– Find (by requester)

– Bind (by requester or invoker)

Web Service = Description + Service

– Service Description

• Details of interfaces (data types, operations, bindings, location, …) • Details of implementation

• Published to registry

– Service

• Software module deployed for invocation

UDDI

WSDL

Service

Search for

Service

Description

Sea c

o

services

Retrieve service

description

Client

Invoke service

Service

SOAP Messages

(3)

Life Cycle of Web Services

• Build

– creation & publication of a service interface

• Deploy

– proceed to the creation and deployment of service

– deployment of the executables for the Web service into an

execution environment

• Run

i

i

f h W b

i

b

h

i

– invocation of the Web service by the service requestor

• Manage

– administration of the Web service application

– Security, availability, performance, OoS

Step 1: Provide Interface of Service

/** * Exchange rate service from country1 to country2 */

public interface IExchange

{

float getRate( String country1, String country2 );

void setValue( String country double value );

void setValue( String country, double value );

double getValue( String country );

(4)

Step 2: Provide Implementation of Service

public class Exchange implements IExchange

{

{

float getRate( String country1, String country2){

return getValue(country1)/ getValue(country2);

}

void setValue( String country, double value ){

}

….. }

double getValue( String country ){

…. }

}

Step 3: Publish the Service

• Step 3 1 : generate standard web service

• Step 3.1 : generate standard web service

description using standard tool (java2wsdl)

• Step 3.2 : start web server on specified url

• Step 3.3 : publish service for SOAP client

(5)

Step 3.1: Create WSDL from interface file

java2wsdl examples.publish.Exchange -e

http://localhost:8004/glue/urn:exchange

Result : - create and write to file “Exchange.wsdl”

value (

blue

= mandatory)

meaning

classname

name of java class to process

-d directory

directory to write files, "." by default

-e endpoint

endpoint of service

-g

include GET/POST binding

-m map-file

read mapping instructions

-n namespace

override default namespace of service

-r description

description of web service

-s

include SOAP binding

-x command-file

command file to execute

Service

WSDL Template

Port

(e.g. http://host/svc) Binding (e.g. SOAP)

portType

Port

Binding

Abstract interface

p

yp

operation(s) inMesage outMessage

(6)

- <definitions name="Exchange" targetNamespace="http://www.themindelectric.com/wsdl/Exchange/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" - xmlns=http://schemas.xmlsoap.org/wsdl/ - --- > - <message name="getValue0SoapIn">

- <part name="country" type="xsd:string"> </part> </message>

- <message name="getValue0SoapOut">

- <part name="Result" type="xsd:double"> </part> </message>

- <message name="setValue1SoapIn">

- <part name="country" type="xsd:string"></part> - <part name="value" type="xsd:double"> </part> </message>

<message name="setValue1SoapOut" /> - <message name="getRate2SoapIn">

- <part name="country1" type="xsd:string"> </part> - <part name="country2" type="xsd:string"></part> </message>

- <message name="getRate2SoapOut">

- <part name="Result" type="xsd:double"> </part> </message>

-<portType name="ExchangeSoap">

i " V l " O d " " - <operation name="getValue" parameterOrder="country">

<input name="getValue0SoapIn" message="tns:getValue0SoapIn" /> <output name="getValue0SoapOut" message="tns:getValue0SoapOut" /> </operation>

- <operation name="setValue" parameterOrder="country value"> <input name="setValue1SoapIn" message="tns:setValue1SoapIn" /> <output name="setValue1SoapOut" message="tns:setValue1SoapOut" /> </operation>

- <operation name="getRate" parameterOrder="country1 country2"> <input name="getRate2SoapIn" message="tns:getRate2SoapIn" /> <output name="getRate2SoapOut" message="tns:getRate2SoapOut" /> </operation>

(7)

<binding name="ExchangeSoap" type="tns:ExchangeSoap">

<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> - <operation name="getValue">

<soap:operation soapAction="getValue" style="rpc" /> - <input name="getValue0SoapIn">

<soap:body use="encoded" namespace="http://tempuri.org/book.soap.Exchange" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />

/i </input>

- <output name="getValue0SoapOut">

<soap:body use="encoded" namespace="http://tempuri.org/book.soap.Exchange" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </output> </operation> </binding> i "E h " <service name="Exchange">

<documentation>An interface for getting exchange rates.</documentation> <port name="ExchangeSoap" binding="tns:ExchangeSoap">

<soap:address location="http://199.174.21.187:8004/soap/exchange" /> </port>

</service>

</definitions>

public class ExchangeServer

{

public static void main( String[] args ) throws Exception {

//

step 3.2 start server

HTTP.startup(

http://localhost:8004/soap

);

// initialize instance of Exchange

Exchange exchange = new Exchange();

exchange.setValue(“usa”, 1);

exchange.setValue(“japan”, 0.4);

// step 3.3 publish

Registry.publish( “urn:exchange”, new exchange());

}

}

(8)

Step 4: Client Invocation of Service

• Step 4 1 : proxy client stub is generated

• Step 4.1 : proxy client stub is generated

dynamically using standard tool (wsdl2java)

• Step 4.2 : client implementation uses the

service by binding and utilizing web service

y

g

g

on specified url

Step 4: Client Interface of Service

package book.soap;

…. import packages …

public class ExchangeClient

{

{

public static void main( String[] args ) throws Exception {

String url = "http://localhost:8004/glue/urn:exchange.wsdl";

// Step 4.1 and 4.2

IExchange exchange = (IExchange)Registry.bind( url, IExchange.class );

// invoke the web service as if it was a local java object

exchange.getRate( "usa", "japan" );

System.out.println( "usa/japan exchange rate = " + rate );

}

(9)
(10)

SOAP

• Service oriented

• Service oriented

architecture

SOAP Request Message

SOAP Request

<?xml version='1.0' encoding='UTF-8'?> <soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' p p p p p g p p xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'> <soap:Body> <n:getRate xmlns:n='http://tempuri.org/examples.service.Exchange'> <country1 xsi:type='xsd:string'>usa</country1> 2 i ' d i ' j / 2 <country2 xsi:type='xsd:string'>japan</country2> </n:getRate> </soap:Body> </soap:Envelope>

(11)

SOAP Response Message

SOAP Response

<?xml version='1.0' encoding='UTF-8'?>?xml version 1.0 encoding UTF 8 ?

<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' soap:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'> <soap:Body> <n:getRateResponse xmlns:n='http://tempuri.org/examples.service.Exchange'> <Result xsi:type='xsd:double'>2.5</Result> </n:getRateResponse> </soap:Body> </soap:Envelope>

Demo

-// running server

> java book.soap.ExchangeServer

//

i

li

t

// running client

> java book.soap.ExchangeClient

(12)

Complete Web Service Description Stack

Service Provider

(13)

WSDL to UDDI Mapping

Reference

• Web Service building blocks for

• Web Service , building blocks for

distributed systems, by Graham Glass

• IBM documentation on

www.ibm.com

References

Related documents

83,3 85,3 96 54,7 75,3 Jumlah 78,92 Bahwa hasil penelitian dan pengisian daftar pertanyaan (koesioner) ke 30 responden terhadap faktor internal yang terdiri dari 5 (lima)

based on Paulo Freire’s (1970) theory of critical literacy and ped- agogy, in which teachers and students engage in active dialogue and reflection, which is facilitated when

Paper Mill: Manufactured in France by Arjo Wiggins (BV-COC-008904) Recommended Label : Recycled (optional to add the 100% moebius loop) Delivery Note / Invoice Text: FSC

There is enough work for the Catholic Church attempt to influence the Healthcare policy to modify the financial system and to support research projects they will develop a new

We saw, in the previous chapter, that we can take the prime fields F p and construct other finite fields from them by adjoining roots of polynomials... By Lemma 6.3, all the elements

Our conclusion is that the classical formulation of the &#34;dutch book argument&#34; may be slightly improved, by stating that the said normalized implied probabilities always

In view of the additional information provided and of the reported relevance of the relations for the work on medical devices, and in order to encourage

As market players are complex entities, having their very own characteristics and objectives, making their decisions and inter- acting with other players, MASCEM was developed as