Web-Service Example Service Oriented Architecture 1 Fundamentals - - PDF document

web service example service oriented architecture
SMART_READER_LITE
LIVE PREVIEW

Web-Service Example Service Oriented Architecture 1 Fundamentals - - PDF document

Web-Service Example Service Oriented Architecture 1 Fundamentals Roles Service provider Service Consumer Registry Operations Publish (by provider) Find (by requester) Bind (by requester or invoker)


slide-1
SLIDE 1

1

Web-Service Example Service Oriented Architecture

slide-2
SLIDE 2

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

  • services

Retrieve service description Client Service Invoke service SOAP Messages

(Standard encoding using XML Schema data types)

slide-3
SLIDE 3

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 );

}

slide-4
SLIDE 4

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
slide-5
SLIDE 5

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
  • verride 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

  • peration(s)

inMesage

  • utMessage
slide-6
SLIDE 6

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> </portType>

slide-7
SLIDE 7

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());

} }

slide-8
SLIDE 8

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

  • n 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 ); } }

slide-9
SLIDE 9

9

SOAP based messaging

slide-10
SLIDE 10

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>

slide-11
SLIDE 11

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

slide-12
SLIDE 12

12

Complete Web Service Description Stack

Service Provider Service Consumer

slide-13
SLIDE 13

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