Thursday, April 18, 2013

ASP .NET web services using jQuery


From the conception to now, web services has gone a long way. Web services use XML as the default data exchange format and SOAP as its protocol. However it has long been dogged by complaints of complexity and lack of open standards. XML as its default message format often feels cumbersome and bandwidth-heavy.

However, with AJAX, JSON overtook XML as a more efficient alternative. It retains all of the advantages claimed by XML, such as being readable and writable for humans, and easy to parse and generate. JSON, though completely language independent, borrows a lot of conventions from languages such as C, C++, C#, Java, JavaScript, Perl, Python, etc. This makes JSON an instant hit among programmers.

To accommodate this trend, data returned from ASP .NET web script services are by default in JSON format.

JSON serialized web service:

EX:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class dummyWebservice : System.Web.Services.WebService
{
  [WebMethod()]
  public string HelloToYou(string name)
  {
      return "Hello " + name;
  }
  [WebMethod()]
  public string sayHello()
  {
      return "hello ";
  } 
}

No comments:

Post a Comment