08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

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.

24<br />

CHAPTER 2 ■ BASICS OF WEB DEVELOPMENT WITH <strong>ASP</strong>.<strong>NET</strong><br />

Figure 2-14. Creating a web reference<br />

Visual Studio will then create a special type of class called a proxy. This is simply a<br />

local representation of the remote service, allowing you to call methods as if they were<br />

implemented on your local computer. However, under the covers, <strong>ASP</strong>.<strong>NET</strong> will forward<br />

all of the proxy method calls to the remote service for execution.<br />

If Visual Studio interprets the file successfully, you will see a list of available methods<br />

(GetStockQuotes in the example in Figure 2-14). You can then create a name for the web<br />

reference <strong>and</strong> add the reference to your project. At this point in your project, you can<br />

create an instance of the web reference proxy class <strong>and</strong> call the method on it to get data<br />

back from the web service.<br />

In fact, let’s do that now so that we can call a remote web service to obtain stock<br />

quotes for our example. Right-click the project name <strong>and</strong> select Add <strong>Web</strong> Reference.<br />

When the Add <strong>Web</strong> Reference dialog box appears, type http://services.xmethods.net/<br />

soap/urn:xmethods-delayed-quotes.wsdl into the URL field <strong>and</strong> click Go. We’ll be using a<br />

service provided by XMethods (www.xmethods.com) that reports delayed stock quotes given<br />

a stock ticker symbol. You can see this in Figure 2-14. After clicking Go, Visual Studio contacts<br />

XMethods, downloads the WSDL, <strong>and</strong> displays the available methods it finds for you<br />

to review. Note the value in the <strong>Web</strong> reference name field (net.xmethods.services), which<br />

will ultimately form the namespace of the proxy class you’ll be using. Change the value<br />

you find there to “QS” for “quote service,” <strong>and</strong> then click Add Reference. At this point,

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

Saved successfully!

Ooh no, something went wrong!