WebServices and Ajax.NET

Michael Schwarz on Monday, August 1, 2005

Some developers asked me if it is possible to use WebServices (WebMethods) in Ajax.NET. Yes, of course, you can add the AjaxMethod attribute to the method. Ok, you do not want to change the WebService source code? My next release will include the possibility to add a simple JavaScript line in your HTML page to access your web services from the client side.

<html> <head> <script language="text/javascript" src="demoservice.asmx?AJAX"></script> </head> <body> <script language="text/javascript"> var x = DemoService.ServerAdd(5, 6); alert(x.value); </script> </body> </html>

That's all! You can use the web service like every Ajax.NET call you have done before, same syntax.

There is only one problem if you want to use web services on different domains. In most browsers it is not allowed to transport data between different domains.