Home > Articles

0672320886

  • Print
  • + Share This

Creating the Web Service Consumer

Now that you have created your proxy, you need to create an ASP.NET Web Forms page to call your Web Service and display the results to the user's Web browser.

  1. Open your favorite text editor, and type in one of the following blocks of code:

    VB Code Listing

  2. <html>
    <head>
    <title>Developer Estimate</title>
    <script language=vb runat=server>
    
        sub btnGo_Click(Sender as Object, E as EventArgs)
    
            dim wsPMCalc as new Pmcalc
            dim intHours as integer
    
            intHours = txtDeveloperEstimate.text.toInt32
    
            lblResult.text = wsPMCalc.DeveloperEstimate(intHours).toString
    
        end sub
    
    </script>
    </head>
    
    <body>
    <form runat=server>
    
      <p align="center"><b>Developer Time Estimate for Project Managers</b></p>
      <p>Enter Developers Estimate: <asp:textbox id=txtDeveloperEstimate 
      size=5 runat=server />
      <asp:button id= btnGo text=Go runat=server onClick=btnGo_Click /></p>
      <p>Modified Projected Estimate: <asp:Label id=lblResult runat=server /></p>
    
    </form>
    </body>
    </html>

    C# Code Listing

    <html>
    <head>
    <title>Developer Estimate</title>
    
    <script language=CSharp runat=server>
    
        public void btnGo_Click(Object Sender, System.EventArgs E) {
    
            Pmcalc wsPMCalc = new Pmcalc();
            Int32 intHours;
    
            intHours = txtDeveloperEstimate.Text.ToInt32();
    
            lblResult.Text = wsPMCalc.DeveloperEstimate(intHours).ToString();
    
        }
    
    </script>
    </head>
    
    <body>
    <form runat=server>
    
      <p align="center"><b>Developer Time Estimate for Project Managers</b></p>
      <p>Enter Developers Estimate: <asp:textbox id=txtDeveloperEstimate 
      size=5 runat=server />
      <asp:button id= btnGo text=Go runat=server onClick=btnGo_Click /></p>
      <p>Modified Projected Estimate: <asp:Label id=lblResult runat=server /></p>
    
    </form>
    </body>
    </html>
  3. Save the file as

  4. c:\pmcalc_web\default.aspx

Examining Your Web Page Code

Before you continue, spend a moment to look at the code. No matter which language you chose to use, there are two things I want to point out. First, notice that you are not using typical HTML form fields. Instead, you are using ASP.NET server-side controls. When these tags are processed on the server, the ASP.NET Web Forms HTTP Handler interprets and renders them as HTML. These Server Side controls give you a high degree of programmability when creating your Web Forms applications.

Second, notice that you have a method called btnGo_Click, which is an event handler that fires when the user clicks the Go button. This "post-back" and event-based programming model is a little different from the "classic" ASP pages you might have created in the past.

After the user fires the btnGo_Click event, a call to the Web Service is made (via the proxy). Notice how your code to reference and call the Web Service treats it as though it were an object residing on your physical system. This is the value of the proxy: to make method calls transparent to the user-programmer.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.