You’ve already seen that ASP.NET will create a page to view in your browser if you navigate to a web service directly, but nine times out of 10 this won’t be how a web service is accessed. Instead, a user will browse to a page that calls the web service behind the scenes for information. In this section, you’ll create a simple web page that consumes the StockTickerSimple web service you just created. As you’ll see, VS2008 does all the heavy lifting for you.
With C16_WebServices still open in VS2008, click File → Add → New Web Site and create a new website called C16_WebServiceClients. Click OK, and you’ll see it appear in the Solution Explorer above C16_WebServices, as shown in Figure 16-6.
Figure 16-6. Two projects in the Solution Explorer
Now delete Default.aspx and add a new web form called StockTickerClient.aspx. This page will consume your web service. To demonstrate, add a
Label control called
lblMessage and two
btnWebService, to the page, as highlighted in Example 16-5. The
Click event handler for
btnWebService will call the web service and display the stock price for Microsoft in
btnPost will cause the page to post back and the
Page_Load handler will show the current time in
Example 16-5. StockTickerClient.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StockTickerClient.aspx.cs" ...