XML Web Services
Dietrich Birngruber
Software Architect
TechTalk
www.techtalk.at
Why XML Web Services?
XML Web Services, D. Birngruber, TechTalk 2
What is an XML Web Service?
XML Web Service =
a “web” of loosely coupled software services
+ programming language independent (client / server)
+ platform independent (runtime, OS)
.NET is one possible solution platform!
XML Web Services, D. Birngruber, TechTalk 3
Independence, because of ...
SOAP
– “RPC” based on XML
– Independent of transport protocol (e.g.: HTTP, SMTP, ...)
– It’s only text! Different implementations and locations:
Java, .NET, Python, Delphi, ..., cell phone, PDA, workstation, ...
– NO distributed object model
(in contrast to CORBA, Java RMI, DCOM, ...)
Web Services Description Language - WSDL (1.1)
– Service (or interface) description in XML
Standardized (W3C)
XML Web Services, D. Birngruber, TechTalk 4
Web Services Scenario
Web
SOAP Web SOAP
Script Client HTTP Service
HTTP Service A
B
SOAP
IIS (default .NET web service container)
Java Client HTTP SOAP
SMTP
Web
SOAP Web SOAP
.NET Client SMTP
Service
HTTP Service C
D
SOAP Java web service Email server +
... Client protocol X
container SOAP processor
SOAP
remote call
protocol
XML Web Services, D. Birngruber, TechTalk 5
Common Web Service Infrastructure
Directory Services Directory
What services are available? Server
Where are they? (URI) (e.g. UDDI)
Description (WSDL)
Clients What messages does
the service understand? XML Web
Service +
RPC (WSDL) Container
What protocol is used? Server
(SOAP via HTTP POST, ...)
XML Web Services, D. Birngruber, TechTalk 6
Contents
Example
SOAP
WSDL
Lookup of Web Services (Discovery)
Resources
XML Web Services, D. Birngruber, TechTalk 7
Example: TimeService
MyFirstService.asmx
<%@ WebService Language="C#" WebService directive
Class="TimeService" %>
using System.Web.Services;
WebService namespace
public class TimeService : WebService { Base class WebService
[WebMethod(Description="Returns the current time")] Attribute [WebMethod]
public string GetTime() {
return System.DateTime.Now.ToLongTimeString();
declares a web service
} method that is callable
via SOAP
}
Who compiles the .asmx file? Who executes our web service?
XML Web Services, D. Birngruber, TechTalk 8
Example: Simple Client in C#
wsdl.exe generates proxy classes (TimeClient.TimeServie)
wsdl.exe /namespace:TimeClient /out:TimeServiceProxy.cs
http://localhost/netsem-ws/MyFirstService.asmx
using System;
using TimeClient; // namespace of the generated proxy
public class NetClient {
public static void Main(string[] args) {
TimeService service = new TimeService();
Console.WriteLine(“Server time: ");
string time = service.GetTime();
Console.WriteLine(time);
}
}
XML Web Services, D. Birngruber, TechTalk 9
Example: Simple Client in Java
Develop proxy by hand, or
Use a tool and library
– E.g.: GLUE
wsdl2Java generates a Java interface (ITimeServiceSoap) and an
implementation class (TimeServiceHelper)
import Kapitel7.GLUEProxy.*; // package of the generated proxy classes
/** Simple client in Java which uses GLUE for accessing web services */
public class JavaClientGLUE {
public static void main(String[] args) {
try {
//use Java interface and proxy class – generated by wsdl2Java
ITimeServiceSoap service = TimeServiceHelper.bind();
String time = service.GetTime();
System.out.println("Server time: \n" + time);
} catch (Exception ex) { ex.printStackTrace(); }
}
}XML Web Services, D. Birngruber, TechTalk 10
Contents
Example
SOAP
WSDL
Lookup of Web Services (Discovery)
Resources
XML Web Services, D. Birngruber, TechTalk 11
SOAP
Independent of a physical transport protocol
– E.g. HTTP, which is request / response oriented
Asynchronous, "one-way" protocol in XML
Least common denominator is one message
– Synchronous method call: combines two messages
1: GetTime_Request
Client 2: GetTime_Response Server
SOAP does not define a
– Distributed object model
– Distributed garbage collection mechanism
– Distributed callback mechanism (no events)
XML Web Services, D. Birngruber, TechTalk 12
XML Layout (simplified, v1.2)
<?xml version="1.0" ?>
<soap:Envelope xmlns:soap="...">
<soap:Header> <!-- (optional and extendable) -->
<m:my xmlns:m="anURI" soap:mustUnderstand=“true" soap:role=“uri2" />
...
</soap:Header>
<soap:Body>
data (depends on encoding and format) or Fault element
<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>
XML Web Services, D. Birngruber, TechTalk 13
Encoding of the Data in the <Body> Element
How does the XML structure look like?
– document (based on an XML schema)
– rpc (based on the SOAP specification)
How are the actual parameters encoded? (e.g. array)
– literal (based on an XML schema)
– encoded (based on the SOAP or custom encoding rules)
Typical combination:
– document/literal (default value in .NET) or
– rpc/encoded (default value for Java server)
XML Web Services, D. Birngruber, TechTalk 14
SOAP-HTTP Binding
HTTP GET
– Sent data is URL encoded and size is limited
– Example: type in a URL in a web browser
http://localhost/netsem-ws/MyFirstService.asmx/GetTime?
HTTP POST
– Sent data is URL encoded, but size of the data is not limited
SOAP via HTTP POST
– Data is SOAP encoded (document/literal, rpc/encoded, ...)
– No restrictions from URL encoding!
XML Web Services, D. Birngruber, TechTalk 15
Useful .NET Namespaces
System.Web.Services
– for creating web services (e.g. WebService, WebMethod)
System.Web.Services.Configuration
– for extending SOAP
System.Web.Services.Description
– for manipulating WSDL
System.Web.Services.Discovery
– for using DISCO
System.Web.Services.Protocols
– Implementation of communication protocols (e.g. SOAP-HTTP)
System.Xml.Serialization
XML Web Services, D. Birngruber, TechTalk 16
What Datatypes Are Supported?
classes, interfaces (e.g. DataSet)
arrays
structs
enumerations
primitive datatypes (int, double, ...)
...
What ever you can define in an XML schema!
Default and custom mapping of XML to runtime types in .NET
XML Web Services, D. Birngruber, TechTalk 17
Example: TimeService2
rpc/encoded
– Attribute [SoapRpcService]
WSDL of the service defines its own XML namespace
– Attribute [WebService]
Method GetTimeDesc has user defined datatype
– Encode fields of class TimeDesc as XML attributes (not elements)
public struct TimeDesc {
[SoapAttribute] public string TimeLong;
[SoapAttribute] public string TimeShort;
[SoapAttribute (AttributeName = "ZoneID")] public int TimeZone;
}
SOAP
<types:TimeDesc id="id1" xsi:type="types:TimeDesc"
types:TimeLong="10:00:25" types:TimeShort="10:00" types:ZoneID="1" />
XML Web Services, D. Birngruber, TechTalk 18
Example: TimeService2
<%@ WebService Language="C#" Class="Kapitel7.TimeService" %>
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
namespace Kapitel7 {
[SoapRpcService]
[WebService(Namespace="http://dotnet.jku.at/time/",Description="Returns the time")]
public class TimeService : WebService {
// ... andere Methoden
[WebMethod(Description="Returns the time description of the server")]
public TimeDesc GetTimeDesc() {
TimeDesc td = new TimeDesc();
// ...
return td;
}
}
public struct TimeDesc { ... }
}
XML Web Services, D. Birngruber, TechTalk 19
Contents
Example
SOAP
WSDL
Lookup of Web Services (Discovery)
Resources
XML Web Services, D. Birngruber, TechTalk 20
WSDL (1.1) Gives the Answers to ...
What „methods“ does the service offer?
What ports, protocols and messages does the service offer in
order to call its methods?
What name and parameters does a message consist of?
What data types are used?
XML Web Services, D. Birngruber, TechTalk 21
Simplified WSDL Layout
<definitions>
<types/> ... describes the datatypes in XML
<message/> ... describes messages (name and parameter)
<portType> ... describes the callable messages for each protocol. The messages
<operation> are grouped togoether to an operation.
<input/> Thus, this elements describe these operations which can be
<output/> reached via this “port”.
<binding> ... binds a protocol to a port and defines the used encoding
<operation/> for each operation (e.g. SOAP, rpc/encoded).
<service> ... describes the identification of a service: name, used bindings
<port/> and the URI under which the service can be reached
</definitions>
XML Web Services, D. Birngruber, TechTalk 22
Web Service Discovery Infrastructure
Universal, Description, Discovery and Integration (UDDI)
– “Yellow Pages“: industry, companies, web services …
– For software not humans
– Scope:
• Within a company (main successful scenario)
• "Global Registry“, everyone is invited (business case????)
– Platform independent: Standardized, Web Service Facade
• www.uddi.org
• IBM, Microsoft, Ariba, Sun, Oracle, Intel, SAP, Boeing, ...
DISCO
– XML document containing URIs to a particular service and WSDL
– Possible result of a UDDI query
...
XML Web Services, D. Birngruber, TechTalk 23
Scenario: Online Book Store
"Book Paradise":
– Online shop, simple user interface
Publisher A, Publisher B:
– Publish their product catalog as a web service
– Precondition: business contract with Book Paradise!!!
2.) Search 1.) Register
UDDI server at
Book Paradise
Web-
Service A
Book 3.) Bind
Paradise 4.) Use Web-
Service B
XML Web Services, D. Birngruber, TechTalk 24
Resources (besides dotnet.jku.at ☺ )
UDDI & Co
– www.uddi.org,
www-3.ibm.com/services/uddi,
uddi.microsoft.com
– www.xmethods.com
Tutorials, Beispiele, Forum, ...
– www.webservices.org
– www.gotdotnet.com
– groups.yahoo.com/group/soapbuilders
Java-Implementierungen
– xml.apache.org/axis/
– www.themindelectric.com
XML Web Services, D. Birngruber, TechTalk 25
Summary
SOAP, WSDL are standardized
Main usage scenario: EAI (Enterprise Application Integration)
e.g.:
.NET GUI Business Logic Data Logic
J2EE GUI Business Logic Data Logic
New standards: security, transactions, …
If you control client and server: binary protocol!
XML Web Services, D. Birngruber, TechTalk 26
Questions + Contact
http://dotnet.jku.at
http://www.ssw.uni-linz.ac.at
http://www.techtalk.at
birngruber@acm.org
XML Web Services, D. Birngruber, TechTalk 27