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.

110<br />

CHAPTER 5 ■ <strong>ASP</strong>.<strong>NET</strong> WEB SERVICES<br />

The code in Listing 5-1 defines a class called Service. As you recall, the <strong>Web</strong>Service<br />

directive specified this class when it defined Service as the implementing class of the web<br />

service logic.<br />

The class is decorated with a couple of attributes. The first one ([<strong>Web</strong>Service<br />

(Namespace = "http://tempuri.org/")]) sets the namespace for your web service. You<br />

should use a namespace when publishing your web service to distinguish it from other<br />

services on the <strong>Web</strong> that may have the same name <strong>and</strong> to help reinforce your br<strong>and</strong>ing.<br />

The second attribute ensures that your web service conforms to the WS-I basic profile.<br />

The WS-I is a group of technology vendors, including Microsoft, who have developed<br />

a set of rules called profiles to define how a web service should work. Profiles ensure that<br />

different technologies won’t prevent web service clients <strong>and</strong> servers from communicating<br />

with each other. The most common profile is called the Basic Profile. In its simplest<br />

sense, the Basic Profile ensures that only data that is common to all technology platforms<br />

can be exposed via a web service. Thus, to conform to the Basic Profile, a Java web service<br />

cannot expose a Java-specific data type such as Vector. Conversely, a .<strong>NET</strong>-based service<br />

cannot expose a .<strong>NET</strong>-specific data type such as DataSet. The <strong>Web</strong>ServiceBinding attribute<br />

([<strong>Web</strong>ServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]) forces your web service<br />

to conform to the Basic Profile version 1.1, thus ensuring interoperability.<br />

Your final responsibility when developing a web service in <strong>ASP</strong>.<strong>NET</strong> is to define which<br />

methods your class will export by using the <strong>Web</strong>Method attribute. Only the methods that<br />

have been attributed with <strong>Web</strong>Method will be exposed to the outside world.<br />

Running Your <strong>Web</strong> Service<br />

When you view the running web service in the browser, you’ll see the <strong>ASP</strong>.<strong>NET</strong> web service<br />

description page. From here, if you select methods from the bulleted list, you can<br />

inspect <strong>and</strong> test the web methods that have been exposed using the <strong>Web</strong>Method attribute.<br />

Should those methods require input parameters, the test page for that method will provide<br />

text boxes for you to enter the parameter values. You can see the test page for the<br />

default Hello World web service in Figure 5-3.

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

Saved successfully!

Ooh no, something went wrong!