Skip to Main Content
Programming ASP.NET 3.5, 4th Edition
book

Programming ASP.NET 3.5, 4th Edition

by Dan Maharry, Dan Hurwitz, Jesse Liberty
October 2008
Intermediate to advanced content levelIntermediate to advanced
1166 pages
28h 31m
English
O'Reilly Media, Inc.
Content preview from Programming ASP.NET 3.5, 4th Edition

Calling the Web Service

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.

Two projects in the Solution Explorer

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 Button controls, btnPost and 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 lblMessage. Clicking btnPost will cause the page to post back and the Page_Load handler will show the current time in lblMessage.

Example 16-5. StockTickerClient.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="StockTickerClient.aspx.cs" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Microsoft® ASP.NET 3.5

Programming Microsoft® ASP.NET 3.5

Dino Esposito
Learning ASP.NET 3.5, 2nd Edition

Learning ASP.NET 3.5, 2nd Edition

Brian MacDonald, Dan Hurwitz, Jesse Liberty
Pro ASP.Net 4 in C# 2010

Pro ASP.Net 4 in C# 2010

Matthew MacDonald, Adam Freeman, Mario Szpuszta
Programming .NET 3.5

Programming .NET 3.5

Jesse Liberty, Alex Horovitz

Publisher Resources

ISBN: 9780596156657Supplemental ContentErrata Page