|
Web ServicesThis introduces basic concepts of web services.
| Topics this page:
|
|
Categories of Web ServicesPublic web services are exposed by Google, Amazon, Yahoo weather, Microsoft UDDI, and Microsoft Exchange Server 2007 SP2+. To build web services, two major vendors provide tools and frameworks. IBM's WebSphere product line and Microsoft's .NET framework. This page contrasts these approaches, beginning with Microsoft's approach.
|
Microsoft .NET Web Service Proxy ArchitectureA client.aspx web page contains calculations made by the web service and accesses the listener.asmx request handler file created as a C# or VB.NET language "ASP.NET Web Service Application" project in Visual Studio. The .asmx file references methods whose structure is defined in a web service proxy.dll library file running in a Virtual Directory within a IIS (Internet Information Service) service (named localhost by default) built into Windows Server. As a binary file, the .dll file is stored in physical folder C:\inetpub\wwwroot\bin so they are picked up automatically by ASP.NET. A Proxy is a stand-in for the real subject at compile time. A proxy has *the same interface* as the original object. A Remote Proxy provides a reference to an object residing in a separate address space, e.g. EJB, RMI, CORBA, etc. RMI stubs acts as a proxy for the skeleton objects. (By contrast, a facade *changes* the interface - generally to make it more coarse grained.) SOAP Request Message Structure The proxy .dll resolves methods defined in an XML file containing WSDL (Web Service Description Language) that describe how to access web services. The code for it is automatically created by the wsdl.exe program that is part of Microsoft's .NET framework 3.5 SDK (in folder C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin) (or \v6.0A for .NET 2.0). |
WSDL (Web Services Description Language)WSDL (Web Services Description Language) are XML files containing descriptions of the methods available. They are contract between a server and its clients. Amazon's S3 WSDL http://s3.amazonaws.com/doc/2006-03-01/AmazonS3.wsdl references .xsd file. Specify this WSDL URL address to a project created in Visual Studio Solution Explorer: right click References, select Add Service Reference, "AmazonS3?" should show in the Services box. Enter a namespace (such as "Amazon.S3").
|
client.aspxThis sample C# web service client code to invoke the Microsoft's UDDI service returns HTML which begins with this: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <businessList generic="1.0" operator="ms.com" truncated="false" xmlns="urn:uddi-org:api"> <businessInfos> <businessInfo businessKey="c13cc7b2-642d-41d0-b2dd-7bb531a18997"> <name>Microsoft DRMS Dev</name> <serviceInfos> <serviceInfo serviceKey="6166f8b2-436d-4001-9f68-f37ff8b47ea3" businessKey="c13cc7b2-642d-41d0-b2dd-7bb531a18997"> <name>Certification</name> ... </serviceInfo> </serviceInfos> </businessInfo> </businessInfos> </businessList> </soap:Body> </soap:Envelope> Only text between <name> tags appear in the web browser. Commands in the Page_Load function are performed upon invocation. In Visual Studio, click on "Add Web Reference" to specify the URL and Name of the WebService. Setting the WebServiceBinding attribute's ConformsTo property to WsiProfiles.BasicProfile1_1 instructs Visual Studio to generate WSDL and ASMX files and other "behind-the-scenes" work, in accordance with the Basic Profile 1.1 (BP 1.1) best practices developed by the Web Services Interoperability Organization (WS-I), a group dedicated to promoting interoperability among Web services developed on different platforms with different programming languages. By default, each new Web service class created in Visual Studio inherits from class System.Web.Services.WebService. |
WSDL Program
C:\>wsdl /language:C# /out:MyProxyClass.cs http://localhost/ASP.NET/MyWebService.asmx
/namespace:mynamespace specifies the namespace of the generated Proxy class. ASP.NET automatically creates WSDL and SOAP documents from .asmx code such as this VB.NET sample: <%@ WebService Language="VBScript" Class="TempConvert" %> Imports System Imports System.Web.Services Public Class TempConvert :Inherits WebService <WebMethod()> Public Function FahrenheitToCelsius (ByVal Fahrenheit As String) As String dim fahr fahr=trim(replace(Fahrenheit,",",".")) if fahr="" or IsNumeric(fahr)=false then return "Error" return ((((fahr) - 32) / 9) * 5) end function <WebMethod()> Public Function CelsiusToFahrenheit (ByVal Celsius As String) As String dim cel cel=trim(replace(Celsius,",",".")) if cel="" or IsNumeric(cel)=false then return "Error" return ((((cel) * 9) / 5) + 32) end function end class 'TempConvert [SoapHeader("timeStamp", Direction=SoapHeaderDirection.InOut)] C# code such as this sample and this sample: <%@ WebService language="C#" class="TempConvert" %> using System; using System.Web.Services; using System.Xml.Serialization; [WebService(Namespace="http://localhost/MyWebServices/")] public class FirstService : WebService { [WebMethod(Description="Add integers")] public int Add(int a, int b) { return a + b; } [WebMethod(Description="Say Hello")] public String SayHello() { return "Hello World"; } } In order for a client to access a Web method, it must be marked with [WebMethod] or [WebMethod()] compiler declarative attribute No method with this WebMethod attribute can be declared static because an instance of that Web service must exist for access by clients. |
Web Service Consuming Amazon Web ServiceThis and this C# client code issues SOAP to the Amazon S3 web service. This creates a object defined in the library specified by a using statement. using System; using System.IO; // for Console.WriteLine() using Amazon.com.amazon.soap; namespace SvcConsumer{ class SvcEater{ public static void Main(String[] args){ // for console program. KeywordRequest kr = new KeywordRequest(); kr.devtag=getAmazonToken(); kr.keyword=this.txtSearch.Text; kr.mode="books"; kr.sort="+titlerank"; kr.tag="webservices-20"; kr.type="lite"; kr.page="1"; ProductInfo pi = srch.KeywordSearchRequest(kr); Details[] allDetails = pi.Details; // showAmazonResult(); // Did the request fail? if (pi.TotalResults > 10){ // get the second page of results kr.page="2"; } ProductInfo pi = srch.KeywordSearchRequest(kr); Details[] allDetails = pi.Details; } // Main } // class SvcEater getAmazonToken(){ return "1234567890"; } showAmazonResult(){ // Replace this code with application event coding: // Console.WriteLine("Calling Hello World Service: " + // mySvc.SayHello()); // Console.WriteLine("Calling Add(2, 3) Service: " + // mySvc.Add(2, 3).ToString()); } } // SvcConsumer Before invoking, change the number in function getAmazonToken() with what Amazona provided. For this application to parse XML content using XMLHTTP and DOM COM object xmlObj.loadXML(), the client machine is dependent on Microsoft XML Parser 3.0 being already installed. This sample SOAP client can also include SOAP Headers with Extensions shows a solution that passes authentication information out-of-band (that is, outside the Web methods' parameter lists) and that "front-ends" each method call with an authentication module that operates independently of the Web methods themselves. |
UDDI WSDL DiscoveryMicrosoft provides a utility to discover disco http://localhost:33973/Service1.asmx?DISCO If the .asmx file does not contain a namespace specification, Microsoft automatically defaults to the http://tempuri.org/ namespace. Microsoft's UDDI Services (Universal Description, Discovery and Integration) Business Registry (UBR). |
Calling Google Web Service
|
IIS Web Service Publishing
To publish a Web Service, configure IIS running on a local machine. Ths sample creates a .NET Webservice in C# that screen scrapes the Microsoft Search Site for any search term. The results are parsed into a SOAP return call containing all the URLs and associated link titles for display. |
Good ole SOAP
|
Chris Dengler's July 2000 SDL wrapper code to returing ADO Recordtypes and arrays with SOAP messaging. Understanding SOAP: The Authoritative Solution by Kennard Scribner |
Client ROPE ProxyA ROPE proxy serves a similiar function as WinSock, through which client software issue and receive communications to web services on a web server.If a SOAP client is on a different computer than the SOAP server, you will need to copy ROPE.dll from the Visual Studio SOAP Toolkit and register it on the client computer (tunning command regsvr32 rope.dll). The ROPE Proxy uses methods in COM objects written to SOAP standard which defines the "handshaking" between client and server. A client first sends a Services Description method ROPE.SDMethodInfo and other methods to discover what web services a particular server provides The ROPE.SoapPackager object creates a SOAP envelope and calls It then calls ROPE.WireTransfer to execute HTTP GET and POST requests by calling methods AddStdSOAPHeaders and PostDataToURI using parameters DataSent and DataReceived. Web Serices Discoverymethods in the ROPE.SDServiceDescriptors collection: <> ROPE.SDEndPointInfo describes the URI location of web services.ROPE.SDMethodInfo provides information about methods exposed by a Web Service. ROPE.SDParameterInfo then provides requirements for calling those methods. SDL = Service Description LanguageHere is a sample request.
<SERVICE>
The SDL wizard can generate this. ASPXML references COM methods.
<%@ language=VB Script %>
ADO
<element name='GetProductsResponse'>
For XML Schema |
|
| Your first name: Your family name: Your location (city, country): Your Email address: |
Top of Page
Thank you! |