Home > Articles > Programming > C#

  • Print
  • + Share This
From the author of

From the author of

Implementing Web Service Logic

Now that proper references to the Web service are available, the program may call Web service functions. The following code from the InvestmentController class shows how to call a Web service function:

     public decimal EstimateReturn()
        InvestmentService.InvestmentService invServ = new InvestmentService.InvestmentService();

        return invServ.EstimateReturn(Principal, Interest, Months);

The implementation of the EstimateReturn() method in the InvestmentController class instantiates a new instance of the InvestmentService class, which is in the InvestmentService namespace. The Web reference to the InvestmentService Web service essentially created a proxy that could be used just like a normal class. All the underlying plumbing necessary to access the Web service is encapsulated within the Web reference. The EstimateReturn() method of the Web service can then be called just like any other instance method.

Running the client application is not functionally different than the InvestmentForm from Part II. The only difference in behavior is that, once the OK button is pressed, it will take longer for the results to come back. This is because of the marshalling and server communication that must take place when invoking the InvestmentService Web service. The results are still the same. Figure 1 shows what the Investment Calculator program looks like, and Figure 2 shows what the message box with results looks like.

Figure 1 The Investment Calculator program.

Figure 2 A message box with program results.

  • + Share This
  • 🔖 Save To Your Account