Team LiB
Previous Section Next Section

9. Develop a Web Application to Call the Serviced Component

This procedure creates a simple ASP.NET Web application that you will use as the client application to call the Web service (via the serviced component).

To develop a Web application to call the serviced component

  1. On the Web service client computer, create a new C# ASP.NET Web application called SecureMathClient.

  2. Add a reference to System.EnterpriseServices

  3. Add a reference to the WebServiceRequestor serviced component.

    Browse to WebServiceRequestor.dll located within the bin\debug folder beneath the WebServiceRequestor project directory.

  4. Open WebForm1.aspx.cs and add the following using statement beneath the existing using statements.

    using WebServiceRequestor;
    
  5. View WebForm1.aspx in Designer mode and create the form shown in Figure 3 using the following IDs:

    • operand1

    • operand2

    • result

    • add


      Figure 3: Web Form control arrangement

  6. Double-click Add to create a button-click event hander.

  7. Add the following code to the event handler.

    Note 

    Set the certPath string to the location of the certificate file that you exported during Procedure 6, “Export the Client Certificate to a File.”

    Set the url string with the HTTPS URL to your Web service.

    private void add_Click(object sender, System.EventArgs e)
    {
      // TODO: Replace with a valid path to your certificate
      string certPath = @"C:\CustomAccountCert.cer";
      // TODO: Replace with a valid URL to your Web service
      string url = "https://wsserver/securemath/math.asmx";
      MathServiceComponent mathComp = new MathServiceComponent();
      
      long addResult = mathComp.CallMathWebService( certPath, 
                                                    url, 
                                                    Int32.Parse(operand1.Text), 
                                                    Int32.Parse(operand2.Text));
      result.Text = addResult.ToString();
    }
    
    
  8. On the Build menu, click Build Solution.

  9. Run the application. Enter two numbers to add, and then click Add.

    The Web application will call the serviced component which will call the Web service using SSL and passing the client certificate.


Team LiB
Previous Section Next Section