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.

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

This isn’t always the case when you use technologies other than <strong>ASP</strong>.<strong>NET</strong>, where you may<br />

end up with differences between your service code <strong>and</strong> its description.<br />

You can see what the default ASMX file markup looks like here:<br />

<br />

It’s pretty straightforward <strong>and</strong> might seem like little more than a file that describes<br />

the language of the code-behind file, the location of the code-behind file, <strong>and</strong> the main<br />

class that implements your service. However, note the . These denote<br />

an <strong>ASP</strong>.<strong>NET</strong> directive <strong>and</strong> tell <strong>ASP</strong>.<strong>NET</strong> to get ready to work its magic. The <strong>Web</strong>Service is the<br />

directive itself, <strong>and</strong> in this case you’re telling <strong>ASP</strong>.<strong>NET</strong> to fire up its web service–processing<br />

infrastructure (if you look back to Listing 3-3, you’ll see another <strong>ASP</strong>.<strong>NET</strong> directive, Page,<br />

which tells <strong>ASP</strong>.<strong>NET</strong> to generate a web page).<br />

The code-behind file is where the action happens in your web service. You can see<br />

the default example in Listing 5-1.<br />

Listing 5-1. Default <strong>Web</strong> Service<br />

using System;<br />

using System.<strong>Web</strong>;<br />

using System.<strong>Web</strong>.Services;<br />

using System.<strong>Web</strong>.Services.Protocols;<br />

[<strong>Web</strong>Service(Namespace = "http://tempuri.org/")]<br />

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

public class Service : System.<strong>Web</strong>.Services.<strong>Web</strong>Service<br />

{<br />

public Service () {<br />

}<br />

//Uncomment the following line if using designed components<br />

//InitializeComponent();<br />

[<strong>Web</strong>Method]<br />

public string HelloWorld() {<br />

return "Hello World";<br />

}<br />

}

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

Saved successfully!

Ooh no, something went wrong!