Service - Drexel University

fishnibblersspongyΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 4 χρόνια και 17 μέρες)

95 εμφανίσεις

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

1

An Introduction to Web Services

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

2

Web Services Architecture

Client

Protocol
-

Specific

Server

Web Service

Container

Web Service

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

3

Web Services Architecture

Client

Protocol
-

Specific

Server

Web Service

Container

Web Service

SOAP over

HTTP/S

SOAP

Native Call

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

4

Web Services Architecture (.Net Scenario)

Client

Web Service

or

Application

Client

Protocol
-

Specific

Server

IIS

Web Server

Web Service

Container

.Net Framework

Web Service

.asmx

Component

SOAP over

HTTP/S

SOAP

Native Call

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

5

Web Services Architecture (Java Scenario)

Client

Web Service

or

Application

Client

Protocol
-

Specific

Server

Apache

Tomcat

JSP/Servlet

Container

Web Service

Container

Apache Axis/SOAP

Web Service

Java

Component

SOAP over

HTTP/S

SOAP

Native Call

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

6

WSDL


The Contract for Invoking a
Service

Client

Web

Service

Infrastructure

Web Service

Call

Web Service

WSDL

Service Spec.

1.
Parse Call

2.
Validate Call Against WSDL

3.
Validate Pass?

1.
YES: Web Service Implementation

2.
NO: Generate and Return Fault

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

7

WSDL


The Web Service Contract

WSDL

Service Interface

Abstract Definition

Service Implementation

Concrete Definition

Messages

Operations

Interface

Binding

Service

Endpoint

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

8

Abstract and Concrete Elements of WSDL

Service Definition

WSDL Document

Abstract

Interface

Definition

Concrete

Implementation

Definition

<definitions>

</definitions>

<interface name = “myIFace”>

<message name = “myMsg”>

<types>

</types >

. . .

</message >

. . .

</interface >

. . .

<service>

<binding name = “Binding1”>

</binding >

. . .

</service >

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

9

Service

WSDL Structure


Name = <Service_Name>

Ports: Collection of Ports

Port

Binding =
<Binding_Name>

Address: Physical Endpoint

Binding

Name = <Binding_Name>

Type =
<PortType_Interface_Name>

Operations: Operation Collection

Operation

Name =
<Port_type_op_Name>

Input name=Logical_In_Op_Name

Output name=Logical_Out_Op_Name

PortType/Interface

Name = <PortType_Interface_Name>

Operations: Operation Collection

Operation

Name = <Port_type_op_Namee>

Input message=
<Message_Name>

Output message=
<Message_Name>


Message

Name = <Nessage_Name>

Parts: Collection of Parts

Part

Name = <Part_Name>

Type =
<
Message_Type>


Type

Name = <Message_Type>

Simple Built In Type OR

ComplexType: XSD Definition of Type

1..*

1..*

1..*

1..*

Concrete

Abstract

Message

Type

Message

Name

Port/Interface Name

Operation Name

Binding

Name

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

10

What is WSDL?

Web Service Description Language

Specifies


Types:

types defined for usage in the messages


Messages:

the messages being exchanged between a client
and a service


Port types / Interfaces:

An abstract set of operations
supported by one or more endpoints (commonly known as
an interface); operations are defined by an exchange of
messages


Bindings:

concrete protocol and data formats for a specific
port type


Service:

a collection of bound ports and addresses

WSDL allows for the automatic generation of service
proxies

Concrete

Abstract

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

11

WSDL Types

The web services standards define a
collection of common types, user
-
defined
types can be specified using XML schema


Example: Array of Strings (“ArrayOf_xsd_string”)

<wsdl:types>


<schema targetNamespace="urn:DirectoryService" xmlns=“…">


<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>


<complexType name="ArrayOf_xsd_string">


<complexContent>


<restriction base="soapenc:Array">


<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>


</restriction>


</complexContent>


</complexType>


</schema>


</wsdl:types>

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

12

WSDL Message

Each message to and from a web service is
modeled via a <message> tag

A given message may have 1 or more parts

Each message part has a name and a type

<wsdl:message name="getFilesInDirRequest">


<wsdl:part name="in0" type="xsd:string"/>

</wsdl:message>


<wsdl:message name="getFilesInDirResponse">


<wsdl:part name="getFilesInDirReturn" type="impl:ArrayOf_xsd_string"/>

</wsdl:message>

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

13

WSDL PortType / Interface

PortType elements have been renamed to
Interface elements

These elements associate messages with the
operations that they will be used for

Defines input, output and fault operations

<wsdl:portType name="DirList2">


<wsdl:operation name="getFilesInDir" parameterOrder="in0">


<wsdl:input message="impl:getFilesInDirRequest"


name="getFilesInDirRequest"/>


<wsdl:output message="impl:getFilesInDirResponse"


name="getFilesInDirResponse"/>


</wsdl:operation>

</wsdl:portType>

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

14

WSDL Bindings

Bindings provide the concrete syntax that
must be used to access operations for
different protocols

<wsdl:binding name="DirectoryServiceSoapBinding" type="impl:DirList2">


<wsdlsoap:binding style="rpc“ transport="http://..."/>


<wsdl:operation name="getFilesInDir">


<wsdlsoap:operation soapAction=""/>


<wsdl:input name="getFilesInDirRequest">


<wsdlsoap:body encodingStyle="http://.../"


namespace="urn:DirectoryService" use="encoded"/>


</wsdl:input>


<wsdl:output name="getFilesInDirResponse">


<wsdlsoap:body encodingStyle=“http://.../"


namespace="urn:DirectoryService" use="encoded"/>


</wsdl:output>


</wsdl:operation>

</wsdl:binding>

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

15

WSDL Services

Service elements encapsulate one or more
physical ports defining an endpoint for the
service


Port definition includes the binding reference

<wsdl:service name="DirList2Service">


<wsdl:port binding="impl:DirectoryServiceSoapBinding"


name="DirectoryService">


<wsdlsoap:address location=


"http://localhost:8080/axis/services/DirectoryService"/>


</wsdl:port>

</wsdl:service>

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

16

WSDL defines a service contract

WSDL

Proxy

Component

Stub

i.e., WSDL2Java

Component

Implementation

WSDL

i.e., Java2WSDL

WSDL can be generated from an implementation or be used

to generate a proxy class

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

17

WSDL is your Service Contract

Approaches:


Contract
-
First


Contract
-
Last


Meet
-
in
-
the
-
Middle

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

18

Contract First

WSDL

Component

Stub

Component

Proxy

Advantages: Optimized Interface,
Portable Interface

Disadvantages: Hard to develop

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

19

Contract Last

Proxy

Component

Stub

Component

Implementation

WSDL

Advantages: No need to know WSDL, Easy

Disadvantages: Non
-
optimized stubs,
portability problems are possible

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

20

Meet
-
In
-
The Middle

Component

Interface

WSDL

Blends the advantages of the contract
-
first and contract
-
last approaches

Hand
-
Optimized

WSDL

Component

Stub

Component

Proxy

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

21

SOAP

SOAP is the web service standard for
encoding requests and responses to
and from web services

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

22

SOAP Structure

SOAP

Envelope

Header


Language, Security, Schema,etc.

Body

Input/Output Message

Fault Information

Extensions


Attachments not governed by SOAP schema

Extensions

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

23

The Body Section…

Document
-
Centric or RPC
-
Centric


Doc
-
Centric is the .Net default, the body
contains an xml representation of the
request/response


RPC
-
Centric is the Java default, the body
contains name/value pairs of the
arguments in the request/response

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

24

SOAP Request
-

.Net

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

25

SOAP Response
-

.Net

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

26

SOAP Request


Axis/Java (RPC
-
Centric)

© Drexel University Software Engineering Research Group (SERG)

http://serg.cs.drexel.edu

27

SOAP Response


Axis/Java (RPC
-
Centric)