WebServices and Ajax.NET
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.
8 Comments
Comments have been disabled for this content.
Wallym said
Excellent information. To be honest, I had wondered if your library had that capability. I am assuming you will be able to call into the web service asynchronously, is that correct?
Wally
Michael Schwarz said
@Wally: yes, of course, you can use both ways like you can do already in the Ajax.NET library. I will upload the new Ajax.NET library this evening...
CIAO
Michael
Wallym said
Thanks for the info. the only reason I asked is that your code sample showed the synchronous way.
JosephCooney said
If you want to call WebServices from the client-side why not just use the WebService dhtml behavior? Is cross-browser support the issue?
Michael Schwarz said
@JosephCooney: Yes, the web service behavior is only working in IE. And the version I used was not able to return a "real" object on the client-side JavaScript.
CIAO
Michael
John said
When will the source code be avaiable?
ROBINA said
I really wonder if the webservice behaviour has some problem returning the real object.For the past one month I have been digging with that stuff and I got very much frustrated with behaviours.Now planning to switch to AJAX.I have been thinking that my code may be wrong.I want to ask michael schwarz if that really have some problem sometimes returning objects?
ROBINA said
I wonder if really that webservice behaviour approach has some problem as michael schwarz stated?I have been digging withthose stuffs for past 1 month.But got frustrated as it couldnt return tha real object thinking that my code might be wrong and now switching to AJAX.Does it really have problem sometimes?