Web development has been moving towards faster and quicker deployment. Popular frameworks such as .NET 2.0 and Prototype.js allow for quick AJAX and web services development, but are rarely used together. Web services made with ASP.NET are usually used along-side with ASP.NET AJAX on ASP pages. However, if your site does not use ASP but you would still like to consume your ASP.NET web services with just JavaScript, then read on.
First, create your ASP.NET web service. Once you are finished, visit the Web.Config file and enter the following under the <system.web> node:
<webservices> <protocols> <add name="HttpGet" /> <add name="HttpPost" /> </protocols> </webservices>
After that’s done with, view your web service’s .asmx file in a web browser. Click the name of a web service operation and you’ll be taken to the operation’s Invoke page. Scroll to the bottom and you can clearly see how to structure your header for calling your web service method using POST or GET:
![]()
You can now use Prototype or another JavaScript method to call the web service. An example AJAX call using POST with Prototype.js could be:
new Ajax.Request('/myws.asmx/HelloWorld', { method: 'post', postBody: 'strName=David', onSuccess: function(transport){ var response = transport.responseText || "no response text"; alert("Success! nn" + response); }, onFailure: function(){ alert('Something went wrong...') } }
hi
i use this method. but i have problem in the iis.
in the iis i get a error that say ” the ‘/myws.asmx/HelloWorld’” dont find.
pls help me
tanks
Comment by muhamad — January 21, 2008 @ 7:46 am
i need de example with “parameter”
thank you!
Emiilano from Argentina
Comment by Emiliano — February 27, 2008 @ 9:48 am
Sounds great! Your blog is one of my most favorite now
. You have hit the nail on the head, just like you always do.
Comment by Raju — April 10, 2008 @ 11:13 pm
After reading through this article, I feel that I need more information on the topic. Could you suggest some more resources please?
Comment by Samuel L. — April 21, 2009 @ 11:42 pm
Very well said, will retweet this one for you
Comment by Simon Slade — April 1, 2010 @ 4:36 am
LOL well now that you put it that way
Comment by Fun Games To Play When Bored — May 19, 2011 @ 1:08 pm
I’ve disappeared in the future combined with added http://adavidchan.com/consuming-aspnet-web-services-with-prototypejs having Askjeeve.org use my girlftriend will see the game a bit too. I only utilised Consuming ASP.NET web services with Prototype.js | David Chan’s Blog whilst the the path trophy around my Get.net take a note of, while i determined if good enough you can reputation your website piece whom, the chances are you wish to see it added like
Comment by gartenhaus.dk — May 21, 2011 @ 6:31 am
Really great post.Thanks so much for the info.
Comment by Jarod Bokman — June 12, 2011 @ 7:35 pm
Thanks a ton! That was really helpful, I just bookmarked your website url.
Comment by make money online — November 10, 2011 @ 5:12 pm
This came up in my reader, just wanted to say thanks.
Comment by Software for contractors — December 15, 2011 @ 8:54 pm
I’m bookmarking http://adavidchan.com/consuming-aspnet-web-services-with-prototypejs so my online fellers would be able to find out about your blog post too. I exactly entered Consuming ASP.NET web services with Prototype.js | David Chan’s Blog as the entry title in my bookmark.
Comment by Haywood Arrez — December 17, 2011 @ 5:27 am
lbujmbebwjedibo, Is proactol safe and effec tine, afjNFvg, [url=http://buydiscountproactol.com/]Proactol[/url], xqCKTGc, http://buydiscountproactol.com/ Proactol, ffoXRjO.
Comment by Proactol — January 30, 2012 @ 9:18 am