Web Service - Network Computing Lab

advertisement
Web Services
Oh-kyoung Kwon
CSD programming languages
lab.
2001.05.24
1
Contents
• Web Services
• Base Technologies
– SOAP
– UDDI
– WSDL
2
Introduction : Until now
• The Web has provided for
– browsing of linked documents
– manually-initiated purchases and
transactions
– 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
Service
Provider
Publish
Bind
Service
Broker
Service
Requester
Find
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
SOAP
Simple Object Access
Protocol
11
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.
Service Oriented Architecture
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
Simplity
• easily be adapted to existing technologies
such as HTTP or SMTP
e.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
SOAP Request Message
message namespace
<SOAP-ENV:Envelope
xmlns:SOAPENV="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
</SOAP-ENV:Body>
Envelope
Namespace
</SOAP-ENV:Envelope>
for
19 wrapping
messages
Deployment
<isd:service xmlns:isd="http://xml.apache.org/xmlsoap/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?";
}
}
20
SOAP Response Message
Resulted
in Body
<SOAP-ENV:Envelope
xmlns:SOAPENV="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>
21
SOAP hides the service
implementation from requester
22
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
23
SOAP consists of
• Envelope
– define a framework for describing what is in a
message and how to process it
• Encoding rules
– expressing instances of application-defined
datatypes
• 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
described, 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
XML Schema)
• Simple value
– one without named parts
– a type that is listed XML Schema such as strings,
integers, 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
distinction
– 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
deploymen
t process
1. deployment
encoding
to xml
2. request
...
check
SOAPActi
on Field
Server
deploymen
t file
rpcrouter
servlet
SOAP
engine
reading
xml & call
method
...
decoding
from xml
3. result
encoding
to xml
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
UDDI
Universal Description,
Discovery, and
Integration
33
Introduction
Interoper Universal Service Interop Protocols
ation
(these layers are not defined yet)
Stack
Universal Description, Discovery
Integration (UDDI)
Simple Object Access Protocol
(SOAP)
Extensible Markup Language (XML)
Common Internet Protocols (HTTP,
TCP/IP)
34
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
35
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, Internetbased 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 preferred36
applications.
Problems UDDI Solves
Broader
B2B
A mid-sized manufacturer
needs to create 400 online
relationships with customers,
each with their own set of
standard and protocols
Describing
Services
Smarter
Search
A flower shop in Australia
wants to be “plugged in” to
every marketplace in the
world, but doesn’t know how
Discover
Services
Easier
Aggregation
A B2B marketplace cannot
get catalog data for relevant
suppliers in its industry,
along with connections to
shippers, insurers, etc.
Integrate
them
Together
37
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
38
SOA Functions
Bind : how an
Publish : how the
provider of a web
service registers itself
Service
Broker
Service
Provider
Find : how an
application connects
to, and interacts with
a web service after
it’s been found
Service
Requester
application finds a
particular web service
39
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
40
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 given web service
41
UDDI4J
• Find a business in the UDDI registry
UDDIProxy 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());
}
42
UDDI4J (cont.)
• Publish a business listing
AuthToken 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 “ +
43
returnedBusinessEntity.getBusinessKey());
UDDI4J (cont.)
• Unpublish a business listing
BusinessList 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());
}
44
Web Service
Describing
Language
Describing Services and
Service Providers
45
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
46
– Some Web Services docs may refer to old names
XML Structure (1/4)
• <definitions> element : contains the
definition of one or more services
<definitions name=“Weather_Service”>
<message> ... What operations the service
<portType> ... provides
<binding> ... How the operations are invoked
<service> ... Where the service is located
</definitions>
47
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>
48
</portType>
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>
49
</binding>
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>
50
WSDK Toolkit
• Stub class generate
java 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
51
Download