taken from:
Web Services Architecture Usage Scenarios,
W3C Working Group Note, 11 February 2004,
http://www.w3.org/TR/2004/NOTE-ws-arch-scenarios-20040211/
3
What are Web Services?
• Middleware for distributed applications
• For remote procedure calls und data exchange
• Open standard based on XML
• For loosely coupled software services
• Independent of programming languages and operating
systems
• Utilizing existing Internet protocols and server architectures
4
Definition Web Service (by W3C)
• Software application identified by URI
• interface description in XML
• with interaction on the basis of XML encoded messages
• and message exchange on the basis of Internet protocols
5
Independence and Integration through ...
• SOAP
– XML standard for message encoding
– independent of transport protocol
– independent of client and server implementations: Java, .NET, Python, …
• Web Services Description Language - WSDL (1.1)
– Interface description in XML
• communication on the basis of existing protocols and server
architectures
– HTTP and Web server
– SMTP and mail server
– FTP and FTP server
• Standardisation (W3C)
– SOAP 1.2, WSDL 1.1 (1.2 und 2.0)
– additional protocols based on SOAP and WSDL
– protocol bindings (HTTP)
6
Web Services Scenario
SOAP
IIS (.NET-Web-Service-Container)
Java-Client HTTP SOAP
SMTP
Web-Server +
SOAP Java-Web-Service- Email-Server +
... Client Protokoll X
Container SOAP-Processor
SOAP
entfernter Aufruf
Protokoll
7
Web Services in Comparison
Java RMI .NET Remoting CORBA Web Services
8
Pros and Cons
• Pros
– independent of programming language, run time environment and
operating system
– built on existing Internet infrastructure
– standardized
– promoted from important players (Microsoft, IBM, SAP, Sun)
• Cons
– performance (XML)
– Not really object oriented
9
Web Service Infrastructure
Discover Services
What services do exist?
Where are they? (URL)
E.g.: UDDI,
DISCO
client(s) Service Description (in WSDL)
What message does the service
know and how are those called?
Service Calls
Using services via
SOAP, HTTP, XML-RPC, ... Web Service
+ container
10
Web Service Architecture
Discovery service
WSD1 URL1
WSD2 URL2
... ...
pu
h
rc
bli
a
sh
se
Web service
container
Client inquiry
Web
Service
call
11
Web Service Architecture (2)
Discovery service
WSD1 URI1
WSD2 URI2
... ...
pu
h
rc
bli
a
sh
se
12
Web Services
Introduction
Web Services in .NET
SOAP
SOAP and .NET
Service Description with WSDL
Preview of MCF
Summary
Web Services in .NET
• IIS and ASP.NET infrastructure support Web services
• .NET Framework provides several
– base classes
– attributes
– protocols
for the realization of Web services
• Visual Studio.NET provides powerful tools for developing
Web services
– implementation
– testing
– administration of IIS
– generation of proxy code (wsdl.exe)
14
.NET Namespaces
• System.Web.Services
– for developing Web services (e.g.: WebService, WebMethod)
• System.Web.Services.Configuration
– for extending SOAP
• System.Web.Services.Description
– for creating and manipulating WSDL descriptions
• System.Web.Services.Discovery
– for using DISCO
• System.Web.Services.Protocols
– for implementation of communication protocols (e.g. SOAP-
HTTP)
• System.Xml.Serialization
– for XML serialization
15
Implementation of Web Services
• in asmx-file with @WebService directive
<%@ WebService Language="C#" Class="MyWebService" %>
17
WebService Description in IE
18
Example: Simple .NET Client
• wsdl.exe generates proxy for client (TimeClient.TimeService)
> wsdl.exe /namespace:TimeClient /out:TimeServiceProxy.cs
http://localhost/netsem-ws/TimeService.asmx
19
Example: Simple Java Client
• Using GLUE tool + Java libraries:
– wsdl2Java create Java interface (ITimeServiceSoap) and proxy
(TimeServiceHelper)
20
Web Services
Introduction
Web Services in .NET
SOAP
SOAP and .NET
Service Description with WSDL
Preview of MCF
Summary
SOAP
• Simple message protocol in XML
– for packaging arbitrary application data
– single messages only (“one-way“)
– asynchronous
• Independent of transport protocol
22
Application of SOAP
• SOAP is extendable
– method call protocol (RPC)
– security
– authentication
– etc.
• Protocol realisation by combination of messages (message exchange
patterns)
– one-way, request-response, multicast, …
1: GetTime_Request
Client 2: GetTime_Response Server
23
SOAP Messages
24
XML Structure (simplified, SOAP 1.2)
<soap:Body>
data (depends on encoding and format)
<soap:Fault>
<soap:Code>...who is responsible?... </Code>
<soap:Reason>...textual description...</soap:Reason>
<soap:Detail>...more error details...</soap:Detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
25
Data in <Body> Part
• Message format:
– document structure defined by XML schema
– rpc structure defined by SOAP for RPC
• Data encoding:
– literal encoding defined by XML schema
– encoded encoding defined by SOAP encoding rules
• Usual combinations:
– document/literal standard in .NET
– rpc/encoded often used by Java servers
26
HTTP Binding
• HTTP-GET, HTTP-POST
– call encoded in HTTP (URL encoded)
– response encoded in XML
Restricted to simple calls (no headers, no structured data)
27
Example: HTTP-POST
Call of GetTime(bool shortForm) of Web service
http://localhost/time/TimeService.asmx
• Call :
http://localhost/time/TimeService.asmx/GetTime?shortForm=true
• HTTP response:
28
Example: SOAP over HTTP (1)
• SOAP over HTTP-POST:
HTTP header SOAPAction
POST /time/TimeService.asmx HTTP/1.1
Content-type: text/xml; charset=utf-8 identifies SOAP request
SOAPAction: http://dotnet.jku.at/GetTime
Content-length: 198
User-Agent: Java1.4.0
Host: localhost
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive
29
Example: SOAP over HTTP (2)
• SOAP encoded response:
30
Web Services
Introduction
Web Services in .NET
SOAP
SOAP and .NET
Service Description with WSDL
Preview of MCF
Summary
SOAP and .NET
.NET provides support for
– defining message format and encoding
– encoding of .NET data types
– development of message headers
– life cycle management
32
Message Format and Encoding (1)
[SoapRpcMethod(
Use=SoapBindingUse.Encoded
Action="http://dotnet.jku.at/Sample/AddAddressRpc“, // SOAP action
RequestNamespace="http://dotnet.jku.at/Sample/Request",
RequestElementName="AddAddressRpcRequest", // SOAP element name
ResponseNamespace="http://dotnet.jku.at/Sample/Response",
ResponseElementName="AddAddressRpcResponse")] // SOAP element name
[WebMethod(Description="Adds an address DataSet for the specified user")]
public void AddAddressRpc(long userID, Address address) { ... }
33
Message Format and Encoding (2)
[SoapDocumentMethod(Use=SoapBindingUse.Literal,
Action="http://dotnet.jku.at/Sample/AddAddressDocLit", // SOAPAction
RequestNamespace="http://dotnet.jku.at/Sample/Request",
RequestElementName="AddAddressDocLitRequest", // SOAP element name
ResponseNamespace="http://dotnet.jku.at/Sample/Response",
ResponseElementName="AddAddressDocLitResponse")] // SOAP element name
[WebMethod(Description="Adds an address DataSet for the specified user")]
public void AddAddressDocLit(long userID, Address address) { ... }
[SoapDocumentService(Use=SoapBindingUse.Encoded)]
public class TimeService : WebService { ... }
34
SOAP Encoding of .NET Data Types
• Serializing of .NET data types
– on the basis of SOAP encoding rules
http://schemas.xmlsoap.org/soap/encoding
– adjusted by attributes (namespace System.Web.Serialization)
35
Example: Encoding of a Type (1)
• Web method GetTimeDesc uses type TimeDesc for return value
36
Example: Encoding of a Type (2)
• SOAP encoded response
...
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ...
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<types:GetTimeDescResponse>
<GetTimeDescResult href="#id1" />
</types:GetTimeDescResponse>
<types:TimeDesc id="id1" xsi:type="types:TimeDesc"
types:TimeLong="10:00:25" types:TimeShort="10:00" types:ZoneID="1" />
</soap:Body>
</soap:Envelope>
37
Including Types
• SoapIncludeAttribute allows inclusion of types
important for specializations
Example: PersonService
<Header>
– e.g. authentication of clients Message Header
<Fault>
Fault Descriptions
41
Classes SoapHeader
and SoapHeaderAttribute
SoapHeader SoapHeaderAttribute
//----- properties //----- properties
public string Actor { get; set; } public SoapHeaderDirection Direction {get; set;}
public bool MustUnderstand { get; set; } public string MemberName {get; set;}
public bool DidUnderstand { get; set; } ...
...
42
Example: AuthHeader
• Identification of user in TimeService
– Login returns identification code (cookie)
– GetTime sends back identification code in header entry
[WebService(Namespace="http://dotnet.jku.at/time/")]
public class HeaderTimeService : WebService {
43
Example: AuthHeader
• Identification of user in TimeService
– Login returns identification code (cookie)
– GetTime sends back identification code in header entry
44
Example: AuthHeader (1)
Identification of user in TimeService
– Login returns identification code (cookie)
– GetTime sends back identification code in header entry
46
Example: AuthHeader (3)
• Client
– creates service proxy and AutHeader object
HeaderTimeService proxy = new HeaderTimeService();
AuthHeader entry = new AuthHeader();
– receives cookie from call to Login
entry.cookie = proxy.Login(user, pwd);
48
Example: StateDemo (1)
Web service StateDemo demonstrates storage of data
<%@ WebService Language="C#" Class="StateDemo" %>
using System.Web.Services;
[WebService(Namespace="http://dotnet.jku.at/StateDemo/")]
public class StateDemo : WebService {
49
Example: StateDemo (2)
[WebMethod(EnableSession=true)]
public int IncSession() {
int hit = (Session["Hit"] == null) ? 0 : (int) Session["Hit"];
hit++;
Session["Hit"] = hit;
return hit;
}
}
50
Web Services
Introduction
Web Services in .NET
SOAP
SOAP and .NET
Service Description with WSDL
Preview of MCF
Summary
Web Service Description Language (WSDL)
• WSDL is an XML-based IDL for Web services
• a WSD describes:
– used data types
– structure of messages
– operations (methods)
– protocols to call operations
– addresses of Web service
52
Structure of WSDL 1.1
<definitions> WSDL description of a Web services
<types> types defined in <xsd:schema>
</types>
<message> simple messages
<part> parts of messages
</part> abstract
</message>
part
<portType> interface specification
<operation> operations of an interface
<input> input message
<output> output message
</operation>
</portType>
<binding> binding of interface to protocols and encoding
<operation> description of the binding for each operation
</binding>
<service> service description concrete
<port> URI and binding to port part
</service>
</definitions>
53
Example: WSDL for TimeService (1)
• WSDL description created by web container (IIS)
http://localhost/WebProject1/TimeService.asmx?WSDL
55
Web Services
Introduction
Web Services in .NET
SOAP
SOAP and .NET
Service Description with WSDL
Preview of MCF
Summary
Microsoft Communication Foundation (MCF)
• MCF shall unite the different architectures for distributed systems
– .NET Remoting
– Web Services
– .NET Enterprise Services
57
Architecture
Kommunikations-Infrastruktur
Communication infrastructure
58
Approach
• Definition of service interface
.NET program
• Implementation of interface
.NET program
• Definition of host
.NET application
IIS
…
• Mapping of service to host
59
MCF Attribute
• MCF uses .NET attributes for service contracts
[ServiceContract]: marking a service interface
60
Example: TimeService with MFC (1)
Interface definition
using System;
using System.ServiceModel; • WCF namespace
namespace WCFTimeService {
61
Example: TimeService with MFC (2)
Interface definition (cont.)
[System.Runtime.Serialization.DataContract] • data part of contract
public class TimeDescDataContract {
private string timeLong;
private string timeShort;
public TimeDescDataContract() {
timeLong = DateTime.Now.ToLongDateString();
timeShort = DateTime.Now.ToShortDateString();
}
}
}
63
Example: TimeService with MFC (3)
ServiceHost application
MCF class ServiceHost facilitates publishing
services under URI
using System;
using System.ServiceModel;
class MyServiceHost {
static ServiceHost myServiceHost = null;
68
Resources (apart from dotnet.jku.at)
• UDDI & Co
www.uddi.org: Homepage of UDDI initiative
www-3.ibm.com/services/uddi: Discovery service from IBM
uddi.microsoft.com: Discovery service from Microsoft
www.xmethods.com: Catalogue with UDDI- und DISCO entries
• For developers
www.w3.org: Specifications
www.webservices.org: Articles and tutorials about Web services
www.gotdotnet.com: Site for .NET technology, including Web services
groups.yahoo.com/group/soapbuilders: Discussion group for SOAP
• Java implementations
xml.apache.org/axis/: Web service server in Java based on Apache
www.themindelectric.com: GLUE: Web service server in Java
69
Dates
Project
– topic can be selected by yourself
– must deal with ASP.NET | ADO.NET | WebServices
– at least 250 lines of code (or 500 lines if combined with C# project)
– deadline: Fr 12. 1. 2007 16:30 – 18:30, SSW Institute
Exam
– Fr. 12.01. 2007, 15:00 – 16:00
70