Skip to main content

Posts

Showing posts from October, 2008

How to call web service in javascript using ASP.Net AJAX?

I wanted to call a web service that is internal to my asp.net web site project in my javascript code and I wanted to call it using the ASP.Net AJAX instead of the usual XMLHttpRequest stuff. So here is what I found. In-order to acheive this lets create a simple web site project and add a very basic service. Lets name it as HelloService (HelloService.asmx). Add a simple web method GetMessage which will accept an integer input and return a string type.  Your HelloService.asmx.cs should look like this. using System.Web.Script.Services; namespace MyServices {     [WebService(Namespace = "http://tempuri.org/")]     [WebServiceBinding(ConformsTo =      WsiProfiles.BasicProfile1_1)]         // To allow this Web Service to be called from script,     // using ASP.NET AJAX.     [ScriptService]         public class HelloService : Syste...