30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 21 ASP .<strong>NET</strong> and Web Services 1045<br />

The next example demonstrates how <strong>to</strong> create a Web-service client and its corresponding<br />

proxy class. We must begin by creating a project and then adding a Web reference<br />

<strong>to</strong> the project. When we add a Web reference <strong>to</strong> a client application, the proxy class is created.<br />

The client then creates an instance of the proxy class, which is in turn used <strong>to</strong> call<br />

methods included in the Web service.<br />

To create a proxy in <strong>Visual</strong> Studio, right click the References folder in Solution<br />

Explorer, and select Add Web Reference (Fig. 21.8). In the Add Web Reference<br />

dialog that appears (Fig. 21.9), enter the Web address of the Web service, and press Enter.<br />

In this chapter, we s<strong>to</strong>re the Web service in the root direc<strong>to</strong>ry of our local Web server<br />

(http://localhost, whose physical location is C:\Inetpub\wwwroot). We do<br />

not s<strong>to</strong>re the services in the VB direc<strong>to</strong>ry used in the previous chapter. For simplicity, we<br />

have instead s<strong>to</strong>red them directly in the root of our Web server. This allows us <strong>to</strong> add a Web<br />

reference without typing in the whole address, by clicking the link Web References on<br />

Local Web Server (Fig. 21.9). Next, we select the appropriate Web service from the list<br />

of Web services located on localhost (Fig. 21.10). Notice that each Web service is<br />

listed as a file with the extension .vsdisco, located in the direc<strong>to</strong>ry for the Web service<br />

project. Files with the extension .disco and .vsdisco are known as discovery files.<br />

We discuss discovery files, as well as the distinction between discovery files with the<br />

.disco and .vsdisco extension later in this section. When the description of the Web<br />

service appears, click Add Reference (Fig. 21.11). This adds <strong>to</strong> the Solution Explorer<br />

(Fig. 21.12) a Web References folder with a node named after the domain name where<br />

the Web service is located. In this case, the name is localhost, because we are using the<br />

local Web server. This means that, when we reference class HugeInteger, we will be<br />

doing so through class HugeInteger in namespace localhost (the Web service class<br />

and proxy class have the same name). <strong>Visual</strong> Studio generates a proxy for the Web service<br />

and adds it as a reference (Fig. 21.12).<br />

Fig. 21.8 Adding a Web service reference <strong>to</strong> a project.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!