Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Client 1
Proxy of Interface 2 UDDI Registry 2
SOAP
Client 2 UDDI Registry 1
Proxy of Interface 1
SOAP
Application 1 WSDL Interface 1
A Web service is an application that exposes Web methods over the Web.
Sharing Objects over the Internet: How?
Discussion Forums:
http://developer.amazonwebservices.com/connect/forumindex.jspa
using System;
using System.Web.Services;
Example: Calc.asmx
Users call http://winserv1.cs.uakron.edu/xiaotest/Calc.asmx up in a
browser.
IIS sends the request to ASP.NET on winserv1.cs.uakron.edu.
ASP.NET compiles Calc.asmx into a DLL.
ASP.NET displays a page that users can test the Add method.
Users Interact with it by clicking the “Add” button.
ASP.NET finds the method name and signature by reading them from
the metadata in the DLL.
It generates an HTML form that users can use to call the Add method
with choice of inputs.
When the users type 2 and 2 into the “a” and “b” boxes and click
Invoke, the XML returned by the Web method appears in a separate
browser window.
Inside Web Services
Inside ASP.NET based Web services
ASMX is a file name extension registered to ASP.NET in
Machine.config.
ASMX files begin with @ WebService directives.
At a minimum, the directive must contain a Class attribute
identifying the class that makes up the Web service.
Web service classes can be attributed with optional
WebService attributes.
Web methods are declared by tagging public methods with
WebMethod attributes.
Helper methods are not exposed by omitting the attribute.
HTTP, XML, and SOAP are hidden under the hood.
The Web methods can be invoked with SOAP, HTTP GET,
and HTTP POST.
They can return output in SOAP responses or simple XML
wrappers.
The WebService Base Class
class CalcService : WebService
[WebMethod (MessageName="AddFloats")]
public float Add (float a, float b)
{ return a + b; }
The Web Services Description Language (WSDL)
SOAP in XML
<s:complexType name="Bookstore">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Name"
nillable="true" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="Address"
nillable="true" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="City"
nillable="true" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="State"
nillable="true" type="s:string" />
</s:sequence>
</s:complexType>
Web Services and Complex Data Types
You can’t pass complex types to a Web method using
HTTP GET and POST. That’s not a limitation if you use
SOAP to invoke Web methods. (ASP.NET generates
test pages using HTTP GET).
Any fields or properties declared in a class or struct
that’s passed to or from a Web method must be public
if they’re to be serialized (transmitted or saved) when
instances of the class or struct are serialized. That’s
because the .NET Framework’s XML serializer will not
serialize nonpublic members.
Examine a WSDL contract:
http://winserv1.cs.uakron.edu/xiaotest/calc.asmx?wsdl
How to Use/Consume Web Services (WS)
Internal (low-level) code for using web services.
HTTP commands for using web services through a
web browser.
How to write a WS client using proxies.
A console-based WS client.
An ASP.NET-based WS client.
For-fee WSs.
Using Get:
GET /calc.asmx/Add?a=2&b=2 HTTP/1.1 Host: www.wintellect.com
a=2&b=2
Client 1
Proxy of Interface 2 UDDI Registry 2
SOAP
Client 2 UDDI Registry 1
Proxy of Interface 1
SOAP
Application 1 WSDL Interface 1
A Web service is an application that exposes Web methods over the Web.
Web Service Clients & Proxies
Web service clients—applications that use, or
consume, Web methods.
In the lab:
Z:
mkdir ws
cd ws
wsdl http://winserv1.cs.uakron.edu/xiaotest/calc.asmx
The resulting <service> tag in the WSDL contract looks like this:
Name=Calculator_x0020_Web_x0020_Service
Wsdl.exe switches:
/out:Calc.cs
/language:vb
/namespace:Calc
/protocol:httpget
/protocol:httppost
/proxy:http://myproxy
A Simple Web Service Client
Write a console client (not a web client) for web service Calc.asmx.
4. Run CalcConsoleClient.exe.
http://winserv1.cs.uakron.edu/xiaotest/CityView/CityView.aspx
Web Services and More
Code-Behind
Asynchronous
For-fee
Web Services and Code-Behind
Coding: Calc2.asmx:
<%@ WebService Class="CalcService" %>
Calc.cs: contains the class code and needs to be
compiled into bin\Calc.dll.
Deploying: Root must be a web application directory (WS-
Calc). http://localhost/calc2.asmx
Benefits: (a) Catches compilation errors before the
service is deployed. (b) Enables to write Web services in
languages that ASP.NET doesn’t natively support.
Asynchronous Method Calls
An asynchronous call returns immediately, no matter how
long the Web service requires to process the call.
System.Web.Services.Protocols.SoapHeader
For-Fee Web Services
Server Side:
header.UserName = "jeffpro";
header.Password = "imbatman";
calc.AuthHeaderValue = header;
[WebMethod (EnableSession="true",
Description="Adds an item to a shopping cart")]
public void AddToCart (Item item)
{ ShoppingCart cart = (ShoppingCart) Session["MyShoppingCart"];
cart.Add (item); }
Web Services
Client 1
Proxy of Interface 2 UDDI Registry 2
SOAP
Client 2 UDDI Registry 1
Proxy of Interface 1
SOAP
Application 1 WSDL Interface 1
A Web service is an application that exposes Web methods over the Web.
Finding Web Services
On a Server (DISCO)
On the Internet (UDDI)
Web Service Discovery—DISCO
How do clients know that a Web service exists?
DISCO (short for “discovery”) is a file-based protocol for
local Web service discovery—that is, for getting a list of
available Web services from DISCO files deployed on
Web servers.
Publish a DISCO file on your Web server that describes
the Web services.
Clients interrogate the DISCO file to find out what Web
services are available and where the services’ WSDL
contracts can be found.
DISCO’s chief disadvantage is that you can’t read a
DISCO file if you don’t have its URL.
Web Service Discovery—DISCO
As an example, to publish two Web services:
http://www.wintellect.com/calc.asmx
http://www.wintellect.com/locator.asmx
Deploy the following DISCO file at a well-known URL on your server.
The contractRef elements identify the URLs of the Web services’
WSDL contracts.
<?xml version="1.0" ?>
<discovery xmlns="http://schemas.xmlsoap.org/disco/"
xmlns:scl="http://schemas.xmlsoap.org/disco/scl/">
<scl:contractRef ref="http://www.wintellect.com/calc.asmx?wsdl"
docRef="http://www.wintellect.com/calc.asmx" />
<scl:contractRef
ref="http://www.wintellect.com/locator.asmx?wsdl"
docRef="http://www.wintellect.com/locator.asmx" />
</discovery>
Web Service Discovery—DISCO
Or deploy a VSDISCO file to enable dynamic discovery. The
following VSDISCO file automatically exposes all ASMX
and DISCO files in a host directory and its subdirectories,
with the exception of those subdirectories noted with
exclude elements:
<?xml version="1.0" ?>
<dynamicDiscovery
xmlns="urn:schemas-dynamicdiscovery:disco.2000-03-17">
<exclude path="_vti_cnf" />
<exclude path="_vti_pvt" />
</dynamicDiscovery>
Web Service Discovery—UDDI
UDDI (Universal Description, Discovery,
and Integration) is a global (Internet)
Web service directory that is itself
implemented as a Web service.
Developed by IBM, Microsoft, and Ariba.
A specification for building distributed
databases that enable interested parties
to “discover” each other’s Web services.
No one company owns the databases;
anyone is free to publish a UDDI-based
business registry.
Operator sites have already been
established by IBM and Microsoft.
Web Service Discovery—UDDI
UDDI sites are themselves Web service sites.
They publish a pair of SOAP-based APIs:
an inquiry API for inquiring about companies
and their Web services
a publisher API for advertising a company’s
Web services (operator sites typically limit
the publisher API to registered members).
Most developers will use high-level tools to
query UDDI business registries and generate
wrapper classes that allow them to place calls
to the Web services.
Referencing Web Services in Visual Studio .NET
Summary:
Web Services (Architecture), Web Methods, WSDL,
SOAP, XML, DISCO, UDDI, Web Service Clients (Stand
Alone, Web Based), Web Service Proxies, For-Fee Web
Services.