1© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
An Introduction to Web Services
2© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
Web Services Architecture
Web ServiceContainer
Protocol-SpecificServer
Client
Web Service
3© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
Web Services Architecture
SOAP
ClientProtocol-SpecificServer
Web ServiceContainer
Web Service
SOAP overHTTP/S
Native Call
4© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
Web Services Architecture (.Net Scenario)
SOAPWeb ServiceContainer
.Net Framework
ClientWeb Service
orApplication
Client
Protocol-SpecificServer
IISWeb Server
Web Service.asmx
Component
SOAP overHTTP/S
Native Call
5© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
Web Services Architecture (Java Scenario)
SOAPWeb ServiceContainer
Apache Axis/SOAP
ClientWeb Service
orApplication
Client
Protocol-SpecificServerApacheTomcat
JSP/ServletContainer Web Service
JavaComponent
SOAP overHTTP/S
Native Call
6© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
WSDL – The Contract for Invoking a Service
ClientWeb
ServiceInfrastructure
Web ServiceCall
Web ServiceWSDL
Service Spec.
1. Parse Call2. Validate Call Against WSDL3. Validate Pass?
1. YES: Web Service Implementation2. NO: Generate and Return Fault
7© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
WSDL – The Web Service Contract
WSDLMessages
Service InterfaceAbstract Definition
Operations
Interface
BindingService Implementation
Concrete Definition Service
Endpoint
8© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
Abstract and Concrete Elements of WSDL
<definitions>
</definitions>
<interface name = “myIFace”>
<message name = “myMsg”>
<types>
</types >. . .
</message >. . .
</interface >. . .
<service><binding name = “Binding1”>
</binding >. . .
</service >
Service Definition WSDL Document
AbstractInterface Definition
ConcreteImplementation
Definition
9© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
WSDL Structure
ServiceName = <Service_Name>Ports: Collection of Ports
BindingName = <Binding_Name>Type = <PortType_Interface_Name>Operations: Operation Collection
PortType/InterfaceName = <PortType_Interface_Name>Operations: Operation Collection
MessageName = <Nessage_Name>Parts: Collection of Parts
TypeName = <Message_Type>Simple Built In Type ORComplexType: XSD Definition of Type
1..*
1..*
1..*
1..*
Conc
rete
Ab
stra
ct
MessageType
MessageName
Port/Interface Name
BindingName
PartName = <Part_Name>Type = <Message_Type>
OperationName = <Port_type_op_Namee>Input message= <Message_Name>Output message= <Message_Name>
PortBinding = <Binding_Name>Address: Physical Endpoint
Operation Name
OperationName = <Port_type_op_Name>Input name=Logical_In_Op_NameOutput name=Logical_Out_Op_Name
10© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
What is WSDL?Web Service Description LanguageSpecifies
Types: types defined for usage in the messagesMessages: the messages being exchanged between a client and a servicePort 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 messagesBindings: concrete protocol and data formats for a specific port typeService: a collection of bound ports and addresses
WSDL allows for the automatic generation of service proxies
Conc
rete
Ab
stra
ct
11© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
WSDL TypesThe 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>
12© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
WSDL MessageEach message to and from a web service is modeled via a <message> tagA given message may have 1 or more partsEach 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>
13© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
WSDL PortType / InterfacePortType elements have been renamed to Interface elementsThese elements associate messages with the operations that they will be used forDefines 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>
14© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
WSDL BindingsBindings 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>
15© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
WSDL ServicesService 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>
16© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
WSDL defines a service contract
ProxyComponent
Stub
i.e., WSDL2JavaWSDL
i.e., Java2WSDLComponentImplementation WSDL
WSDL can be generated from an implementation or be usedto generate a proxy class
17© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
WSDL is your Service Contract
Approaches:Contract-FirstContract-LastMeet-in-the-Middle
18© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
Contract First
ComponentStubWSDL
ComponentProxy
Advantages: Optimized Interface, Portable InterfaceDisadvantages: Hard to develop
19© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
Contract Last
ComponentImplementation WSDL
ProxyComponent
Stub
Advantages: No need to know WSDL, EasyDisadvantages: Non-optimized stubs, portability problems are possible
20© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
Meet-In-The Middle
ComponentInterface WSDL
ComponentStub
ComponentProxy
Hand-OptimizedWSDL
Blends the advantages of the contract-first and contract-last approaches
21© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
SOAP
SOAP is the web service standard for encoding requests and responses to and from web services
22© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
SOAP Structure
SOAP
HeaderLanguage, Security, Schema,etc.
Envelope BodyInput/Output Message
Fault Information
ExtensionsAttachments not governed by SOAP schema
Extensions
23© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
The Body Section…
Document-Centric or RPC-CentricDoc-Centric is the .Net default, the body contains an xml representation of the request/responseRPC-Centric is the Java default, the body contains name/value pairs of the arguments in the request/response
24© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
SOAP Request - .Net
25© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
SOAP Response - .Net
26© Drexel University Software Engineering Research Group (SERG)http://serg.cs.drexel.edu
SOAP Request – Axis/Java (RPC-Centric)