inally the moment of truth has arrived. The first released version of Microsoft's .NET Framework is available for Win 2k, Win NT and XP versions at Microsoft Downloads. Anyone can download the framework by itself, but you need an MSDN subscription to download the released version of Visual Studio .NET.
Creating both HTML clients and Windows clients to consume Web services is straightforward. You'll also see a way to create proxy objects using the Visual Studio .NET IDE. This method is much easier than using the command line utilities.
You'll be using the same Web service used for my previous article in this series. Please refer to that article for the details about the Web service.
Ways to Consume Web Services using HTTP.
There are two ways you can consume Web services using HTTP.
- Directly access the Web Service using HTTP
- Build an HTML client to consume the Web Service
Accessing Web services directly using HTTP is a feature that's built in to the .NET framework. The framework automatically generates a page that lets you enter parameter arguments and call the Web service from its origin. You don't need to create any special code to make this workall you need is a browserin other words, you don't need to create a special client just to test a .NET Web service.
You can invoke the Web Service using the HTTP GET method. The syntax for directly calling the Web service using HTTP GET is:
http://ServerName/WebServiceName.asmx/WebMethodName?
Argument1=Argument1Value&...ArgumentN=ArgumentNValue
| Author Note: This automatic test feature is only available for MS .NET Web services. Unfortunately most of other SOAP implementations do not support this method. For example my company used a stock brokering Web Service in our WAP client which was based on a Java implementation called GLUE, but that SOAP platform does not support the GET method. |
Another example based on the MS .NET Framework, the Book Price Comparison Web Service is a handy Web Service that accepts a ISBN number and returns a list of prices in different online book stores. It exposes a web method called "CompareBookPrices" which accepts one argument called "BookISBN".
For example, suppose you want to look for a book called "Professional C# Web Services". This book is based on MS Web Services and discusses Web services in great detail and I highly recommend it for further reading on Web Services. (Disclaimer: I'm biased, because I'm one of the authors, but it also means that I happen to know the ISBN number of the book). Using that book for the BookISBN parameter, here's the URL to access the Web Service directly.
http://hosting.msugs.ch/aravindc/BookPriceComparison.
asmx/CompareBookPrices?BookISBN=1861004397
You can try it yourself by clicking Compare Book Prices. The Web service returns the results in XML as a list of <Seller> tags containing the requested price comparison information. Here's a short excerpt:
<?xml version="1.0" encoding="utf-8" ?>
<Book ISBN="1861004397" Title="Professional C# Web
Services" Author="Wrox Author Team" Format="Trade
Paperback" Published="December 2001" ListPrice="$
59.99">
<Seller Name="BooksAMillion">
<ItemCost>$37.79</ItemCost>
<Availability>
Ships within 2-3 days.
</Availability>
<ShippingType>UPS (3-7)</ShippingType>
<ApproximateShippingCost>
$ 3.98
</ApproximateShippingCost>
<TotalCost>$41.77</TotalCost>
</Seller>
<Seller Name="BookPool">
<ItemCost>$38.50</ItemCost>
<Availability>
Out of stock
</Availability>
<ShippingType>UPS Ground (2-7)</ShippingType>
<ApproximateShippingCost>
$ 3.95
</ApproximateShippingCost>
<TotalCost>$42.45</TotalCost>
</Seller>
<!-- more results here -->
</Book>
|