9.9. Creating the Service Consumer Web Form

In this section, you build a Web page that uses the preceding WCF service. As with a Web service, Visual Web Developer handles most of the plumbing to discover what the service expects as parameters and what it returns.

The Web form in this example displays a list of time zones that uses daylight time for part of the year. The user selects a time zone and clicks a button. This action transmits the time zone name to the WCF service and displays the calculated results. To create the consumer page, follow these steps:

  1. Add an ASP.NET page named usesvc.aspx to the project.

    NOTE

    This book uses the single-file model for ASP.NET pages, so you need to uncheck the Place Code In Separate File check box.

  2. In Design view, add DropDownList, Button, and Label controls to the page.

  3. Double-click a blank area of the page to create a default handler routine for the Page Load event and then add the following code inside the routine:

    If Not IsPostBack Then
       Dim q = From tz In _
         TimeZoneInfo.GetSystemTimeZones() _
           Where tz.SupportsDaylightSavingTime _
           Select sname = tz.StandardName, _
           dname = tz.DaylightName Order By sname
       DropDownList1.DataSource = q
       DropDownList1.DataTextField = "dname"
       DropDownList1.DataValueField = "sname"
       DropDownList1.DataBind()
    End If

    This code uses a LINQ query to look through the Web server's time zone information and select only the time zones that support daylight time. The query extracts the standard time zone name and the daylight ...

Get ASP.NET 3.5 For Dummies® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.