How Does Vsnet Help

To create a Web Service, you add class and method attributes that identify a class as a Web Service and identify the publicly exposed methods (called WebMethods). When you do that, VS.NET automatically creates XML documents that help you find and consume the Web Service. Using these documents, VS.NET also automatically creates a Web Service Description page that shows you the title of the Web Service as well as the set of operations it supports (see Figure 21.1).

Figure 21.1: Web Service Description page generated automatically by VS.NET

Figure 21.1: Web Service Description page generated automatically by VS.NET

When you click the operation links, VS.NET provides a Web Form you can use to test each operation. For example, if you click the getPayment link shown in Figure 21.1, you'll see the page in Figure 21.2.

Figure 21.2: The Web Method Operation page generated automatically by VS.NET

The page also shows you sample Simple Object Access Protocol (SOAP) request and response documents. You'll see how to use SOAP with Web Services later in this chapter. Finally, the Web Method Operation page shows get and post requests and responses for the WebMethod.

For example, the getPayment WebMethod shown in Figure 21.2 calculates a mortgage payment. The WebMethod requires three parameters—the APR (AnnualPercentageRate), the amount of the loan (TotalCost), and the mortgage duration in years (DurationInYears). If you look at the bottom of the Web Form, you'll see that a get request generates a simple XML document that returns a string element containing the monthly payment amount (see Figure 21.3).

W ft-ltwiq ii * ljrnpHI \f 'j-c l ricui il Jrr rv-ipe&ir 'hi p]ac4lHl4rri iKrwi mid Is si irIihI tdi acta, i ->¡li.ai. (it i- .-jlk^tuj.. - aj 1/raj j-| i itv.'i.-- . -jr l^*>ufrr. 'ujuiitm . iiu>jrtairaj< i lk| lIul a-LCui l'aLc lk-j i-il l-j.-il tyf-4 i (.<■ 4t i'kjal- m.hjip jit 1

Figure 21.3: VS-generated sample get request and response for the getPayment Web-Method

The bottom half of the second box in Figure 21.3 shows the response XML. When you fill in the fields and post the form, you can quickly test the return values from your Web Service methods using the get method. For example, when you send 6.5 as the annual percentage rate, $200,000 for the loan amount, and 30 as the mortgage duration, the Web Service calculates the monthly payment and returns the XML document shown in Figure 21.4.

■ wm ™—warns* . ■ maniEicasxMawwirrffKbum■ w i - i ft (J, V«r pjru.fl. »«L .Jt

jj j] 'j j.5p*ih cjj^j^,- "^timm > j

(i.1 *ilais 1 -iflit*^ 3t">iw-rj.-i*".'*«or»1«(.v. 1 aflf*.-ktiwryr*otrffc*j

u*4 h

j

f :r-j wnnr:1] 0 incrrin-ji'iih-f. ■ ■*

j

fjU^w trvniMf

Figure 21.4: XML response from the get request for the getPayment WebMethod

Figure 21.4: XML response from the get request for the getPayment WebMethod

In the next sections, you'll create the Mortgage Payment Calculator Web Service and consume it from a browser, from a Windows Forms .NET application, and from a VB6 client application.

Was this article helpful?

0 0

Post a comment