1 Web Services Oh-kyoung Kwon CSD programming languages lab. 2001.05.24.

Post on 30-Mar-2015

220 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

Transcript

1

Web Services

Oh-kyoung Kwon

CSD programming languages lab.

2001.05.24

2

Contents

• Web Services

• Base Technologies– SOAP– UDDI– WSDL

Introduction : Until now

• The Web has provided for– browsing of linked documents– manually-initiated purchases and transacti

ons– downloading files

• all of this is manual, by way of a browser

Introduction : Web Services

• Web Services is a new model for using the Web– transactions initiated automatically by a program,

not necessarily using a browser– can be described, published, discovered, and

invoked dynamically in a distributed computing environment

– new ways of using the web: intelligent agents, marketplaces, auctions

• all built on XML and other internet standards!

What are Web Services?

• The next evolution of e-business– abstraction beyond object-oriented technology– publishing of business functions to the Web– universal access to these functions

• A natural extension to the client-server model– transaction model for e-business – layered services: server can also be a client of

services • shift from client-server to peer-to-peer architecture

Examples of Web Services

• Business Information with rich content– weather reports, credit check, news feed, credit card

validation, airline schedules, request for quote, stock quotes

• Transactional Web Services for B2B or B2C– airline reservations, supply chain management, rental car

agreements, purchase order

• Aggregation– future application will be built from web services that are

dynamically selected at runtime based on their cost, quality and availability.

Features

• Interoperability– Any Web service can interact with any other Web service

• Ubiquity– any device which supports standard protocols can both host

and access Web services

• Low barrier to Entry– concept is easy, and free toolkits allow developers to create

and deploy Web services

• Industry Support– .NET framework

SOA : Service Oriented Architecture

ServiceProvider

ServiceRequester

ServiceBroker

Bind

Find

Publish

SOA : Details

• Service Provider– provides e-business services– PUBLISHES availability of these services through a registry

• Service Requestor– FINDS required services via the Service Broker– BINDS to services via Service Provider

• Service Broker– provides support for publishing and locating services– like telephone yellow pages

Base Technologies

• SOAP - Simple Object Access Protocol– an XML protocol to invoke a method on a server to execute– a requested operation and get a response in XML– request message is sent by service requestor– response message is sent by service provider

• UDDI - Universal Description, Discovery, Integration– UDDI servers act as a directory of available services and

service providers– SOAP can be used to query UDDI for services

• WSDL - Web Services Description Language– an XML vocabulary to describe service interfaces

11

SOAP

Simple Object Access Protocol

Simple Object Access Protocol

• Brief History

• Features : pros and cons

• SOAP structure

• SOAP/HTML Request and Response

• Examples using Apache-SOAP

RPC processes versus OO interactions

• OO interactions– you invoke a method, that method

completes, and the result is returned

• RPC– message-based

• A message was sent to the server• at some point, a message saying "OK, I'm

done" will be received from that server

It’s SOAP Time

• The data sent to the machine has to be encoded– RPC : XDR(External Data Representation) encoding

format– XML-RPC : XML, 98

• SOAP : 2 items added to XML-RPC– envelope, which carries information about the

included message– a set of rules for encoding application-specific data

types.

Simple Object Access Protocol

• SOAP 1.0: Userland, Microsoft, DevelopMentor– SOAP 1.0 was specific to COM and HTTP

• SOAP 1.1 (April 23, 2000) - includes– contributions from IBM and Lotus– substitutable Transport bindings (not just HTTP)– substitutable Language bindings (e.g. Java)– substitutable Data encodings (pluggable)– completely vendor-neutral– independent of: programming language, object model, operating system, or platform

Service Oriented Architecture

Simplity

• easily be adapted to existing technologies such as HTTP or SMTPe.g) attempt to turn web servers into object servers

(middle-tier servers in a three-tier architecture)

• Drawback– limited to inheritance, lacks transaction

management

Simplity (cont.)

• SOAP is a text-based protocol, while others are binary protocols– debug, firewall(easy for intermediaries to process

message)

• SOAP appeals to all vendors– Microsoft .NET Framework– IBM has also created an excellent SOAP toolkit for

Java programmers– ebXML (OASIS and UN)

SOAP Message Structure

• Request and Response messages– Request invokes a method on a remote object– Response returns result of running the method

• SOAP defines an "envelope"– "envelope" wraps the message itself– message is a different vocabulary– namespace prefix is used to distinguish the two parts message

application-specific message vocabulary

SOAP vocabulary

19

SOAP Request Message

<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.w3.org/1999/XMLSchema">

<SOAP-ENV:Body> <ns1:sayHelloTo xmlns:ns1=“urn:Hello" SOAP-ENV:encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/">

         <name xsi:type ="xsd:string“> John </name> </ns1:sayHelloTo></SOAP-ENV:Body>

</SOAP-ENV:Envelope>

SOAPEnvelope

Namespacefor wrapping

messages

message namespace

20

Deployment<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment" id="urn:Hello"> <isd:provider type="java" scope="Application" methods="sayHelloTo"> <isd:java class="hello.HelloServer“ static="false"/>  </isd:provider> </isd:service>

package hello;public class HelloServer {   public String sayHelloTo(String name)   {      return "Hello " + name + ", How are you doing?";    } }

21

SOAP Response Message

<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.w3.org/1999/XMLSchema"><SOAP-ENV:Body>

          <ns1:sayHelloToResponse  xmlns:ns1="Hello" SOAP-ENV:encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/">                 <return xsi:type="xsd:string">

Hello John, How are you doing? </return>

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

Resulted in Body

22

SOAP hides the serviceimplementation from requester

23

Client Java Program

// Build the call.Call call = new Call();call.setTargetObjectURI("urn:Hello");call.setMethodName("sayHelloTo");call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); Vector params = new Vector(); params.addElement(new Parameter("name", String.class, name, null));call.setParams(params);

// Invoke the call.Response resp = call.invoke(“http://localhost:8080/apachesoap/servlet/rpcrouter“, "");

Client Java Program

SOAP consists of

• Envelope– define a framework for describing what is in a mes

sage and how to process it

• Encoding rules– expressing instances of application-defined dataty

pes

• RPC representation– representing RPCs and responses

Envelope

• Header– who should deal with a feature(SOAP actor)– where it is optional or mandatory(mustUnderstand)

• Body– container for mandatory information– include following information

• RPC calls• Fault element

Encoding rules

• based on a simple type system that is a generalization of the common features

• operates on two levels– given a schema consistent with the type system d

escribed, a schema for an XML grammar maybe constructor

– given a schema and a particular graph of value, an XML instance may be constructed

• “http://schemas.xmlsoap.org/soap/encoding”

Encoding rules (cont.)

• The value of type is determined by– xsi:type attribute– reference to a schema (notation is described by X

ML Schema)

• Simple value– one without named parts – a type that is listed XML Schema such as strings, i

ntegers, enumerated values, arrays of bytes

Encoding rules (cont.)

• Compound value– aggregation of relations to other values– encoded as a sequence of elements– array : ordinal position servers as the distin

ction– struct : element name is the distinction

RPC representation

• To make a method call, following is needed– The URI of the target object– A method name– An optional method signature– The parameters to the method– Optional header data

• method calls and responses are both carried in the SOAP Body element

Using SOAP in HTTP

• HTTP application must use the media type “text/xml”

• binding only defines SOAP within HTTP POST requests

• use SOAPAction HTTP Header Field when issuing a SOAP HTTP Request

• follows the semantics of the HTTP Status code

SOAP/HTTP Request and Response

Client Server

1. deployment

2. request

deployment file

rpcrouter servlet

encoding to xml

decoding from xml

deployment process

...

3. result

SOAP engine

...

encoding to xml

reading xml & call method

check SOAPAction

Field

Examples• Xmethods.com

– SOAP Service provider• Service Name:Currency Exchange Rate• XMethods ID Number:5• Service Owner:xmethods• Contact Email:support@xmethods.net • Description:Exchange rate between any two currencies, Takes in country1 and

country2, and returns the exchange rate between currencies SOAP Endpoint URL:http://services.xmethods.net:80/soap

• SOAPAction:None Needed• Method Namespace URI:urn:xmethods-CurrencyExchange• Method Name(s):getRate• WSDL URL : http://www.xmethods.net/sd/CurrencyExchangeService.wsdl  

33

UDDI

Universal Description,

Discovery, and

Integration

34

Introduction

Interoperation

Stack

Universal Service Interop Protocols (these layers are not defined yet)

Universal Description, Discovery Integration (UDDI)

Simple Object Access Protocol (SOAP)

Extensible Markup Language (XML)

Common Internet Protocols (HTTP, TCP/IP)

35

What is UDDI?

• Universal Description, Discovery, and Integration

• A project to speed interoperability and adoption for web services– Standards-based specifications for service

description and discovery– Shared operation of a web-based business registry– Partnership among industry and business leaders -

more than 70 companies have signed up so far

36

UDDI.org

• Discover businesses worldwide that offer the exact products and services that you need.

• Register the products and services of your own business for others to discover. Or both.

• Technology and business champions are leading the development and deployment of an open, Internet-based Universal Description, Discovery, and Integration (UDDI) specification.

• UDDI is the building block that will enable businesses to quickly, easily and dynamically find and transact business with one another using their preferred applications.

37

Problems UDDI Solves

Broader B2B

Smarter Search

Easier Aggregation

A mid-sized manufacturer needs to create 400 online relationships with customers, each with their own set of standard and protocols

A flower shop in Australia wants to be “plugged in” to every marketplace in the world, but doesn’t know how

A B2B marketplace cannot get catalog data for relevant suppliers in its industry, along with connections to shippers, insurers, etc.

Describing Services

Discover Services

Integrate them Together

38

UDDI Vision and Process

1. Start with existing standards– TCP/IP, HTTP, XML– Industry-specific schemas– Shared vision of open protocols

2. Augment and implement via a Web Service– Common web services “stack”– Shared implementation to avoid confusing customers– Public specs, open service, inclusive process

39

SOA Functions

ServiceProvider

ServiceRequester

ServiceBroker

Bind : how an application connects to, and interacts with a web service after it’s been found

Find : how an application finds a particular web service

Publish : how the provider of a web service registers itself

40

Registry Data

• White pages : information such as the name, address, and telephone number of a given business

• Yellow pages : information that categorizes business. Based on existing standards

• Green pages : technical information about the web services provided by a given business

41

Service Types• Business Information (BusinessEntity)

– services, categories, contracts, URLs, and other things necessary to interact with a given business

• Service Information (BusinessService)– describe a group of web services

• Binding Information (BindingTemplate)– the technical details necessary to invoke a web service. URLs,

method names, argument types...

• Information about specifications for services (TModel)– metadata about the various specification implemented by a giv

en web service

42

UDDI4J

• Find a business in the UDDI registryUDDIProxy proxy = new UDDIProxy();proxy.setInquiryURL(“http://www.abc.com/uddi registry/inquiryapi”);proxy.setPulibshURL(“https://www.abc.com/uddi registry/protect/publishapi”);

BusinessList bl = proxy.find_business(“S”, null, 0);

Vector businessInfoVector = bi.getBusinessInfos.getBusinessInfoVector();for (int i=0;i<businessInfoVector.size();i++) {

BusinessInfo businessInfo = (BusinessInfo)businessInfoVector.elementAt(i);

System.out.println(businessInfo.getNameString());}

43

UDDI4J (cont.)

• Publish a business listingAuthToken token = proxy.get_authToken(“userid”, “password”);

Vector entities = new Vector();BusinessEntity be = new BusinessEntity(“”);be.setName(“Sample business”);entities.addElement(be);

BusinessDetail bd = proxy.save_business(token.getAuthInfoString(), entries);

Vector businessEntities = bd.getBusinessEntityVector();BusinessEntity returnedBusinessEntity = (BusinessEntity) (businessEntities.elementAt(0));System.out.println(“Returned businessKey “ + returnedBusinessEntity.getBusinessKey());

44

UDDI4J (cont.)

• Unpublish a business listingBusinessList bl = proxy.find_business(“Sample business”, null, 0);

Vector businessInfoVector = bi.getBusinessInfos.getBusinessInfoVector();for (int i=0;i<businessInfoVector.size();i++) {

BusinessInfo bi = (BusinessInfo)businessInfoVector.elementAt(i);

System.out.println(“Business key : “ + bi.getBusinessKey());

DispositionReport dr = proxy.delete_business(token.getAuthInfoString(),

bi.getBusinessKey());

}

45

Web Service Describing Language

Describing Services and

Service Providers

46

What is WSDL

• describe XML-based network services regardless of communication protocol and request structure

• XML equivalent of a resume– what a web service can do– where it resides– how to invoke

• WSDL is the convergence of IBM's NASSL and Microsoft's SDL– Some Web Services docs may refer to old names

47

XML Structure (1/4)

• <definitions> element : contains the definition of one or more services

<definitions name=“Weather_Service”><message> ... <portType> ... <binding> ... How the operations are invoked<service> ... Where the service is located

</definitions>

What operations the service provides

48

XML Structure (2/4)

• What operations the service provides

<message name = “IngetTempRequest”><part name=“meth1_inType1” type=“xsd:string”/>

</message><message name = “IngetTempResponse”>

<part name=“meth1_outType1” type=“xsd:string”/></message>

<portType name=“Weather_Service”><operation name=“getTemp”>

<input message=“IngetTempRequest”/><output message=“IngetTempResponse”/>

</operation></portType>

49

XML Structure (3/4)

• How the operations are invoked

<binding name=“Weather_ServiceBinding” type=“Weather_Service”><soap:binding style=“rpc” /><operation name=“getTemp”> <soap:operation soapAction=”urn:weather-service”/>

<input> <soap:body encodingStyle=“...”

namespace=“urn:weather-service”use=“encoded”/>

</input><output> <soap:body encodingStyle=“...”

namespace=“urn:weather-service”use=“encoded”/>

</output></operation>

</binding>

50

XML Structure (4/4)

• Where the service is located

<service name=“Weather_Service”><port binding=“Weather_ServiceBinding”

name=“Weather_ServicePort”><soap:address location=“

http://localhost:8080/soap/servlet/rcproupter”/></port>

</service>

51

WSDK Toolkit

• Stub class generatejava com.ibm.wsdl.Main –in Wheather_Service.wsdl

Weather_ServiceProxy class

Weather_ServiceProxy weather = new Weather_ServiceProxy();float temp = weather.getTemp(“75248”);System.out.println(“temp = “ + temp);

test client program

top related