25
An Introduction to Web Services An Introduction to Web Services Sriram Krishnan, Ph.D. [email protected]

An Introduction to Web Services Sriram Krishnan, Ph.D. [email protected]

Embed Size (px)

Citation preview

Page 1: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

An Introduction to Web ServicesAn Introduction to Web Services

Sriram Krishnan, [email protected]

Page 2: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Web Services: DefinitionWeb Services: Definition

• Many different definitions are available• IBM (Gottschalk, et al): A web service is an

interface that describes a collection of operations that are network accessible through standardized XML messaging.

• Microsoft (on MSDN): A programmable application logic accessible using standard Internet protocols.

• Another Web Service definition:– A network service that provides a programmatic

interface to remote clients

Page 3: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Web Services: RequirementsWeb Services: Requirements

• Accessible through standard Web protocols– Interoperability is important

• Standard description language

• Publishable to a registry of services

• Discoverable via standard mechanisms

Page 4: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Web Services: FeaturesWeb Services: Features

• Independent of programming language and OS• Not bound to any single platform or specific

protocol• All information required to contact a service

is captured by the Web Service Description– Web Services Description encapsulates an interface

definition, data types being used, and the protocol information

Page 5: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Web Services ArchitectureWeb Services Architecture

ServiceRegistry

ServiceRequestor

ServiceProvider

Lookup Publish

Interact

Page 6: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Need to know three things about WSNeed to know three things about WS

• What does the service do?

• How is the service accessed?

• Where is the service located?

Page 7: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

WSDLWSDL

• Web Services Definition Language (WSDL)• Standard to describe the invocation syntax of a

Web Service• Authors: IBM, Microsoft and others• WSDL is an XML document that describes

– Interface types for each port– Content of messages it receives and sends– Bindings of interfaces to protocols

• SOAP is default, others possible• Describes the access points (host/port) for the protocol

Page 8: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Web Services StackWeb Services Stack

Service Discovery Layer

Service Description Layer

Service Messaging Layer

Service Transport Layer

Page 9: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

WSDL ElementsWSDL Elements

• PortTypes• Message• Types• Binding• Port• Service

SoapStruct echoStruct(SoapStruct ss)

Page 10: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

WSDL: TypesWSDL: Types• Types: collection of all data types used in the Web service

(any schema language can be used, typically XML Schemas)– referenced by messages

<types> <schema xmlns="http://www.w3.org/2001/XMLSchema"> <complexType name="SOAPStruct"> <all> <element name="varString" type="string"/> <element name="varInt" type="int"/> </all> </complexType> </schema></types>

Page 11: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

WSDL: MessageWSDL: Message

• Message: abstract, typed definition of the data being sent

<message name="echoStructRequest">

<part name="inputStruct“ type="s:SOAPStruct"/>

</message>

<message name="echoStructResponse">

<part name="return" type="s:SOAPStruct"/>

</message>

Page 12: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

WSDL: PortTypeWSDL: PortType

• portType: an abstract set of operations supported by one or more endpoints

<portType name="TestPortType">

<operation name="echoStruct">

<input message="tns:echoStructRequest"/>

<output message="tns:echoStructResponse"/>

</operation>

</portType>

Page 13: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

WSDL: BindingWSDL: Binding

• Protocol Binding: details of how elements in PortType are converted into concrete representations

<binding name="TestSoapBinding" type="tns:TestPortType"> <soap:binding style="rpc“ transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="echoStruct"> <soap:operation soapAction="http://test.org/"/> <input> <soap:body use="encoded" namespace="http://test.org/"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <soap:body use="encoded" namespace="http://test.org/"

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation></binding>

Page 14: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

WSDL: Service and PortWSDL: Service and Port• Service: a named collection of ports• Port: how a binding is deployed to a particular

endpoint <service name="TestService"> <port binding="tns:TestSoapBinding“ name="echo"> <soap:address location="http://test.org:5049/serv/echo"/> </port> </service>

Page 15: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Three properties of a Web serviceThree properties of a Web service

• PortType: What does the service do?

• Binding: How is the service accessed?

• Service: Where is the service located?

Page 16: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Web Services StackWeb Services Stack

Service Discovery Layer: WSIL, UDDI

Service Description Layer: WSDL, RDF

Service Messaging Layer: SOAP

Service Transport Layer: HTTP, SMTP

Page 17: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

WSDL Information ModelWSDL Information Model

• Separation between– Abstract specification – Concrete implementation of specification

• In WSDL– Abstract: portType + messages– Concrete: service + port + binding

Page 18: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

SOAPSOAP

• SOAP = HTTP + XML• XML

– De facto standard for representing data in a platform independent way

• HTTP– Simple universally supported protocol

• Interoperability:– Easily understood Network Protocol: HTTP – Common Data Format: XML

Page 19: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Characteristics of SOAPCharacteristics of SOAP

• XML based• Internet-based• Independent of

– Programming language– Transport mechanism

• Can be used with protocols other than HTTP– SMTP: Simple Mail Transfer Protocol– JMS: Java Message Service

Page 20: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Example of SOAP request Example of SOAP request

POST /serv/echo HTTP/1.1Host: www.test.orgContent-Type: text/xmlContent-Length: 357SoapAction:” http://test.org/”

<SOAP-ENV:Envelopexmlns:SOAP-ENV = http://schemas…envelope”

SOAP-ENV:encodingStyle=“http://…/encoding”> <SOAP-ENV:Body>

<m:echoStructRequest xmlns:m=“http://test.org/”> <inputStruct>

<varString>Stay Classy, San Diego!</varString><varInt>2006</varInt>

</inputStruct></m:echoStructRequest>

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

Page 21: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Example of SOAP responseExample of SOAP response

HTTP/1.1 200 OKContent-Type: text/xmlContent-Length: 343

<SOAP-ENV:Envelopexmlns:SOAP-ENV=“http://…/envelope/”SOAP-ENV:encoding=“http://…/encoding/”><SOAP-ENV:Body> <m:echoStructResponse xmlns=“http://../”>

<return> <varString>I am Ron Burgundy?</varString>

<varInt>2006</varInt> </return>

</m:echoStructResponse> </SOAP-ENV:Body></SOAP-Env:Envelope>

Page 22: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Web Service ToolkitsWeb Service Toolkits

• Apache Axis: http://ws.apache.org/axis/– One of the most popular toolkits– User by several projects here like NBCR,

GEON, CAMERA, GLEON

• Microsoft .NET: http://msdn.microsoft.com/webservices/

• SUN: http://java.sun.com/webservices/• Several other lightweight implementations:

XSUL, ZSI (Python), SOAP::Lite (Perl)

Page 23: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Writing a Web Service: Apache Axis Writing a Web Service: Apache Axis

• Define a Web service interface– Use WSDL to define port types, messages,

and data types

• Use a stub compiler to generate Java sources– WSDL2Java generates client and server side

bindings from the WSDL– Also generates Web Services Deployment

Descriptors (WSDD)

Page 24: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

Writing a Web Service: Apache Axis (contd.) Writing a Web Service: Apache Axis (contd.)

• Implement the service implementation (server-side)

• Deploy the service into a Container– Jakarta Tomcat: http://tomcat.apache.org/– Hosting environment - provides desirable features

such as reliability, scalability, security, etc

• Write custom clients based on the generated stubs– Can also write clients in other languages, viz. Python,

Javascript, Perl, etc

Page 25: An Introduction to Web Services Sriram Krishnan, Ph.D. sriram@sdsc.edu

SummarySummary

• Hopefully, we have a better idea of what Web services are– What? How? Where?

• Next, we will see how Web services are applicable to the scientific community