XML Web Services

graphics/new_icon.jpg

With the release of the Microsoft .NET Framework, XML Web services appeared on the Internet scene. XML Web services are perhaps one of the most misunderstood technologies available to Web developers today. Because XML Web services return their data in XML format, many developers are unsure of how to use them and what advantages they offer over more traditional methods of data generation.

In fact, Web services fill a very important need in the world of Web development. They provide a means for developers to feed data to applications running on multiple platforms and being delivered on multiple devices with a minimal amount of effort. Because the data returned by a Web service is in XML format, the Web service itself doesn't have to be concerned with what kind of application consumes that data.

The Web service architecture is quite complex, but using a Web service is not. A Web service typically has one or more methods that can be called and that will return data based on information passed to them. A method is simply a piece of programming code designed to perform a certain task. In the context of Web services, a Web method is used to take data that you pass it, process that data, and return additional data in the form of an XML response.

A good example of the use of a Web service is a stock quote service. Suppose that you wanted to provide your Web site with real-time stock quotes for any stock symbol your site visitor requests. A Web service is the perfect solution. The Web service can take the stock symbol, access information stores of stock value data, determine the value of the stock, and then return the value of the stock in XML format. Because the value is returned in XML format, it can easily be used in a Web page, a Windows application, a cell phone application, or any other device that can consume a Web service. The developer of the Web service doesn't have to be concerned with how the content will be displayed. That's the sheer beauty of Web services.

Many Web services are available for public use and can be used in your Web applications. For a searchable list, visit http://uddi.microsoft.com/search. Click on the tModels tab and enter a search string such as stock. A list of XML Web services is returned, as shown in Figure 34.5.

Figure 34.5. Microsoft's UDDI Web site provides access to Web services you can use in your applications.

graphics/34fig05.gif

Select one of the Web services listed in the results window and then click the Overview tab to see the URL for the overview document. An overview document is written in XML and displays all the information required for the Web service to work. It consists of a link to a .asmx file with ?WSDL at the end of the link. If you browse to the link without the ?WSDL, you can run the Web service from within your Web browser. In Figure 34.6, you can see the .asmx page for a Web service's method called GetQuote. By entering a stock symbol in the text box and clicking Invoke, you can run the Web service. Figure 34.7 shows the results of the GetQuote method when the stock symbol MSFT is passed to it. The page shown here is an example of a test page provided by all Web services. In a real-world environment, you would call the Web service programmatically and not from a Web page.

Figure 34.6. This page allows you to test the GetQuote method of the StockQuote Web service.

graphics/34fig06.gif

Figure 34.7. By entering MSFT into the StockQuote Web service, XML data is returned detailing the stock performance of Microsoft.

graphics/34fig07.gif

To add a reference to the GetQuote Web Service, follow these steps:

  1. Select Data, Insert Data View to display the Data Source Catalog.

  2. Click the Add to Catalog link under the XML Web Services section of the Data Source Catalog as shown in Figure 34.8.

    Figure 34.8. Add a new data source to the Data Source Catalog using the Add to Catalog link.

    graphics/34fig08.gif

  3. In the Service Description Location text box, enter http://www.webservicex.net/stockquote.asmx?WSDL.

  4. Click Connect Now to access the Web Service and populate the Data Source Properties dialog box as shown in Figure 34.9.

    Figure 34.9. The Data Source Properties dialog box provides all the information necessary to use the Web Service.

    graphics/34fig09.jpg

  5. Click the Modify button to display the Parameter dialog box as shown in Figure 34.10.

    Figure 34.10. The Parameter dialog box allows you to send a parameter to the Web Service.

    graphics/34fig10.gif

  6. Enter MSFT in the Value text box and click OK.

  7. Click OK to add the new data source to the Data Source Catalog.

When a Data view is inserted using a Web Service, the data returned is in XML format. In order to format the data for display on a Web page, you will need to write some XSL to format the data. XSL is a formatting language that is used to format XML data. A discussion of XSL is outside of the scope of this book, but for a comprehensive explanation of XSL and how to use it to format data, read Special Edition Using XSLT from Que Publishing.



Special Edition Using Microsoft Office FrontPage 2003
Special Edition Using Microsoft Office FrontPage 2003
ISBN: 0789729547
EAN: 2147483647
Year: 2003
Pages: 443

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net