Web Services Dr. Herbert PraehoferInstitute for System Software Johannes Kepler University LinzDr. Dietrich BirngruberSoftware Architect TechTalkwww.techtalk.at
Web Services
Introduction
Web Services in .NET
SOAP
SOAP and .NET
Service Description with WSDL
Discovery of Web Services: UDDI and DISCO
Preview of Web Services .NET 2.0
Summary
Motivation
Example: Travel Agent Service 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/
Integration of heterogonous, distributed systems
globally distributed
different programming languages
different APIs
B2C and B2B applications
Usage of globally distributed services
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
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
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)
Web Services Scenario
Web Services in Comparison
Web, Mail, FTP server ORBs .NET remoting infrastructure Java RMI infrastructure Infrastructure SOAP ORB/CDR .NET object serialisation Java object serialisation Packaging HTTP, HTTPS, SMTP, FTP GIOP/IIOP binary or OAP RMI-IIOP Transport protocol XML data IDL-specified objects .NET objects Java objects Data structures WSDL (XML-based) CORBA IDL C# Interfaces Java Interfaces Interface definition independent independent .NET languages (C#, VB.NET, ..) Java Programming language Web services CORBA .NET Remoting Java RMI
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)
Web Service Infrastructure
Web Service Architecture
Web Service Architecture (2)
Web Services
Introduction
Web Services in .NET
SOAP
SOAP and .NET
Service Description with WSDL
Discovery of Web Services: UDDI and DISCO
Preview of Web Services .NET 2.0
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)
.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
Implementation of Web Services
asmx-File in a virtual directory in the IIS public class MyWebService : WebService { deriving from base class System.Web.Services.WebService [WebMethod(Description= “comment ")]
[…]
public Returntype MyWebMethod( …) {
… Identification and settings by .NET attributes
identification of web service methods
definition of format and encoding
XML namespaces and element names to use
etc.
<%@ WebService Language="C#" Class="MyWebService" %>
in asmx-file with @WebService directive
Example: TimeService
TimeService.asmx WebService directive deriving from WebService Attribute [WebMethod] identifies web service method stored in virtual directory
time/TimeService.asmx <%@ WebService Language="C#" Class="TimeService" %>
using System;
using System.Web.Services;
public class TimeService : WebService {
[WebMethod(Description="Returns the current time")]
public string GetTime(bool shortForm) {
if (shortform) return DateTime.Now.ToShortTimeString();
else return DateTime.Now.ToLongTimeString();
}
}
WebService Description in IE
Example: Simple .NET Client
using System;
using TimeClient; //Namespace des erzeugten Proxies
public class NetClient {
public static void Main(string[] args) {
TimeService service = new TimeService();
Console.WriteLine("Die Zeit am Server ist: ");
string time = service.GetTime(true);
Console.WriteLine(time);
}
}
Client program creates TimeService object and calls GetTime > wsdl.exe /namespace:TimeClient /out:TimeServiceProxy.cs http://localhost/netsem-ws/MyFirstService.asmx wsdl.exe generated proxy for client (TimeClient.TimeService)
Example: Simple Java Client
import Kapitel7.GLUEProxy.*; // import generated GLUE proxy classes
/** Simple XML web service client in Java using GLUE */
public class JavaClientGLUE {
public static void main(String[] args) {
try {
// Calling service using class and interface generated by wsdl2java
ITimeServiceSoap service = TimeServiceHelper.bind();
String time = service.GetTime(true);
System.out.println(“The time on the server is: \n" + time);
} catch (Exception ex) { ex.printStackTrace(); }
}
} Using GLUE tool + Java libraries:
wsdl2Java create Java interface (ITimeServiceSoap) and proxy (TimeServiceHelper)
Comments