Title: Introduction to Web Services in the Microsoft 'Net Framework
1Introduction to Web Servicesin the Microsoft
.Net Framework
2Contents
- Introduction to Web Services
- Introduction to Web Services in the Microsoft
.Net Framework - A Web Services Example Microsofts .NET My
Services - Creating a Web Service in Visual Studio .Net
- Consuming a Web Service in Visual Studio .Net
3Introduction to Web Services
4Defining Web Services
- A web service is a chunk of functionality that
can be accessed using web technology - Across an intranet or the Internet
- Usually
- Whats accessed is a method in a language such as
Java or Visual Basic.NET - The web technology used is the Simple Object
Access Protocol (SOAP) carried over HTTP - Both the .NET and Java camps have endorsed web
services
5Key Web Services Technologies
- Web Services Description Language (WSDL)
- An IDL for web services
- Simple Object Access Protocol (SOAP)
- An XML-based protocol for web services
- Universal Description, Discovery, and Integration
(UDDI) - A directory service for web services
6Illustrating Web Services Technologies
UDDI Registry
Internet
UDDI Registry
Application
Application
Application
WSDL Interface
7Applying Web Services (1)
- Connecting clients to Internet applications
- One example is Microsofts .NET My Services
- B2B integration on the Internet
- The next generation of EDI
- Enterprise application integration (EAI) on
intranets - A standard approach to connecting all applications
8Applying Web Services (2)
Internet
9Describing Web Services WSDL
- Created by Microsoft and IBM
- Recently handed to the World Wide Web Consortium
(W3C) - Endorsed by everybody
- Microsoft, IBM, Sun, Oracle, BEA, more
10Accessing Web Services SOAP
- The Simple Object Access Protocol (SOAP) allows
invoking operations - SOAP defines an XML-based format for parameters
- SOAP requests/responses can ride on
- HTTP
- The most common case today
- SMTP or MSMQ
- For loosely-coupled interactions
- Other protocols
11What SOAP Provides
- Industry agreement
- Its endorsed by Microsoft, IBM, Sun, Oracle,
BEA, Iona, and others - Object model independence
- SOAP isnt tied to any operating system,
programming language, or object model - Support for diverse protocols
- Synchronous and asynchronous
12Illustrating A SOAP Message
Envelope
Headers
Body
Method
Parameters
13An Example SOAP Request (1)
- POST /AccountAccess HTTP/1.1
- Host www.qwickbank.com
- Content-Type text/xml charsetutf-8
- Content-Length 305
- SOAPAction
- ltSOAP-ENVEnvelope
- xmlnsSOAP-ENV
- "http//schemas.xmlsoap.org/soap/envelope/"
- SOAP-ENVencodingStyle
- "http//schemas.xmlsoap.org/soap/encoding/"gt
14An Example SOAP Request (2)
- ltSOAP-ENVBodygt
- ltmGetBalance
- xmlnsm"http//www.qwickbank.com/bank"gt
- ltAccountgt729-1269-4785lt/Accountgt
- lt/mGetBalancegt
- lt/SOAP-ENVBody gt
- lt/SOAP-ENVEnvelopegt
15An Example SOAP Response (1)
- HTTP/1.1 200 OK
- Content-Type text/xml charset"utf-8"
- Content-Length 304
- ltSOAP-ENVEnvelope
- xmlnsSOAP-ENV
- "http//schemas.xmlsoap.org/soap/envelope/"
- SOAP-ENVencodingStyle
- "http//schemas.xmlsoap.org/soap/encoding/"gt
16An Example SOAP Response (2)
- ltSOAP-ENVBodygt
- ltmGetBalanceResponse
- xmlnsm"http//www.qwickbank.com/bank"gt
- ltBalancegt3,822.55lt/Balancegt
- lt/mGetBalanceResponsegt
- lt/SOAP-ENVBody gt
- lt/SOAP-ENVEnvelopegt
17Discovering Web Services UDDI
- Universal Description, Discovery, and Integration
(UDDI) provides a specialized directory service
for discovering compatible web services - It uses XML
- Its endorsed by Microsoft, IBM, Ariba, Oracle,
Sun, BEA, and more - An organization can create an XML-defined
business registration - Which can contain information about various
available web services
18Illustrating A UDDI Business Registration
19The Trouble With UDDI (2000)
- Its complicated
- Microsofts .NET Framework ships a simpler
discovery mechanism called Disco for use on
intranets - Its not being used for web services yet
- Many businesses are registered, but not many WSDL
definitions - Without WSDL, developers cant build
interoperable web services clients
20Introduction to Web Services in the Microsoft
.Net Framework
21ASP.NET
- The next generation of ASP (Active Server Pages)
- It looks similar, but its actually very
different - Allows creating two kinds of applications
- Browser applications
- Rely on .aspx pages
- Web services applications
- Rely on .asmx pages
22Illustrating a Web Services Application
IIS
class X WebMethod public int Method1()
SOAP
app.asmx
ADO.NET
Common Language Runtime
DBMS
23Exposing Web Services An Example .asmx Page (1)
- lt_at_ WebService Language"c" Class"Compute" gt
- using System.Web.Services
- public class Compute
-
- WebMethod public int Factorial(int f)
-
- int i
- int result 1
- for (i2 iltf i)
- result result i
- return result
-
24Exposing Web Services An Example .asmx Page (2)
- WebMethod public double SquareRoot(double s)
-
- return System.Math.Sqrt(s)
-
-
25XML Web Services Protocol Stack
Internet Protocols
Directory of services UDDI
Service discovery DISCO
Microsoft specific ?
Service descriptions WSDL
Service interactions SOAP
Universal type system XSD
Universal data format XML
Ubiquitous communication Internet
26Web Services
Application Concepts
Data
Schema
Services
Invocation
27Web Services with .NET
public class OrderProcessor WebMethod
public void SubmitOrder(PurchaseOrder order)
... XmlRoot("Order", Namespace"urnacme.b2b
-schema.v1") public class PurchaseOrder
XmlElement("shipTo") public string ShipTo
XmlElement("billTo") public string BillTo
XmlElement("comment") public string Comment
XmlElement("items") public Item Items
XmlAttribute("date") public DateTime
OrderDate
public class OrderProcessor public void
SubmitOrder(PurchaseOrder order) ... public
class PurchaseOrder public string ShipTo
public string BillTo public string Comment
public Item Items public DateTime
OrderDate
lt?xml version"1.0" encoding"utf-8"?gt ltsoapEnvel
opegt ltsoapBodygt ltSubmitOrdergt ltOrder
date"20010703"gt ltshipTogtManuel
Costalt/shipTogt ltbillTogtBill
Gateslt/billTogt ltcommentgtOvernight
deliverylt/commentgt ltitemsgt
ltproductIdgt17748933lt/productIdgt
ltdescriptiongtDom Perignonlt/descriptiongt
lt/itemsgt lt/Ordergt lt/SubmitOrdergt
lt/soapBodygt lt/soapEnvelopegt
Order order new Order() order.ShipTo "Manuel
Costa" order.BillTo "Bill Gates" order.OrderDa
te DateTime.Today OrderProcessor.SubmitOrder(
order)
28A Web Services Example Microsofts .NET My
Services
29A Web Services Example Microsofts .NET My
Services
- .NET My Services is a set of Internet-accessible
web services that store data about users - The data is described using XML
- Applications can access that data
- Access is via SOAP
- Users control which applications are allowed to
access which parts of their data
30Illustrating .NET My Services
.NET My Services
Internet
Clients
31Describing .NET My Services
- Passport
- Based on Kerberos
- .NET Alerts
- .NET Services
- .NET Contacts
- .NET Locations
- .NET Calendar
- More
32A .NET My Services Request
SOAP request - Service name - PUID -
Kerberos ticket - Method(Parameters)
.NET My Services Applications
.NET My Services
SOAP response
33.NET Services (Mark)
.NET Contacts (Mark)
Passport Service
.NET Services (Bob)
Booking Application
.NET Alerts (Bob)
.NET Locations (Bob)
34Creating a Web Service in Visual Studio .Net
35Creating a ASP.NET Web Service Project
36Changing the Web Service Name
37Accessing the Code Behind
38Understanding the Code Behind
inheritance is optional (useful to create state
full web services)
39Editing the Code Behind
attribute that tells that this method should be
exposed as a web service method
40Understanding the .asmx page
In this case, everything is in the code behind
41Build
42Files Generated
43Testing with a Browser
44Viewing the dynamically generated WSDL (1)
45Viewing the dynamically generated WSDL (2)
46Consuming a Web Service in Visual Studio .Net
47Creating a ASP. NET Web Application
48Adding a Reference to the Web Service
49Viewing the Proxy Class Created Behind the Scenes
50Designing the web page
51Calling the web service
52Running the client application
53Sources
- Seminário "Understanding .Net", David Chappell,
FEUP, 2000 - Seminário "Introduction to .NET", Manuel Costa,
FEUP, 2001