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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

312<br />

CHAPTER 13 ■ <strong>AJAX</strong> SCRIPTS AND SERVICES<br />

}<br />

}<br />

<strong>Web</strong>Next.House.registerClass('<strong>Web</strong>Next.House', null, Sys.IDisposable);<br />

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();<br />

You can then ensure that it is correctly <strong>and</strong> cleanly delivered to the browser by<br />

declaring it as a script that the ScriptManager component will manage for you. Here’s<br />

the markup to achieve this:<br />

<br />

<br />

<br />

<br />

<br />

Using <strong>Web</strong> Services from Script<br />

A very powerful facet of the ScriptManager is that it allows you to declare references to<br />

web services. If these services are attributed as scriptable, <strong>and</strong> thus generate a JavaScript<br />

proxy, the ScriptManager can then initialize everything that is needed for a client to communicate<br />

directly with the service.<br />

For example, consider the following simple web service. Note that it has been attributed<br />

as a [ScriptService]. In order to do this, you’ll need to add a using reference to the<br />

System.<strong>Web</strong>.Script.Services namespace.<br />

<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 />

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

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

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

[ScriptService]<br />

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

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

public int AddEm(int x, int y) {

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

Saved successfully!

Ooh no, something went wrong!