Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to create Ajax Enabled Webservice in .Net 2.0

JavaScript
function Likes_Count() {

            debugger;
       // alert(row);
       $.ajax({
           type: "POST",
           contentType: "application/json; charset=utf-8",
           url: "http://localhost:1157/WebSite2/likes/likesservice.asmx/LikesCount",
           //data: '{"Cat":' + cat + ',"title":' + title + '}',
           data: "{ 'Cat': '" + cat + "','title': '" + title + "'}",
           dataType: "json",
           success: function (data) {
               $("#likes_count").html(data.d);
           },
           error: function (result) {
               alert("Error");
           }
       });

   }

   window.onload = Likes_Count;



webservice code


C#
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.Services;
using System.Web.Script.Services;

/// <summary>
/// Summary description for LikesService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
    [ScriptService]
public class LikesService : System.Web.Services.WebService {

    public LikesService () {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    [WebMethod]
    public string AddLikes(string cat, string title)
    {
        return cat;
       
    }

    [WebMethod]
    public string[] Likes_Count()
    {
        string[] arr4 = new string[1];
        arr4[0] = "Success";
        return arr4;
    }

    [WebMethod]
    public string LikesCount(string Cat, string title)
    {

        return "98948";
        
    }

}



System.Web.Script.Services namespace is not found in .net 2.0. but found in 3.5 and 4.0
this code works well in 3.5 and 4.0

so please tell the alternate way to create ajax enabled webservice in .net 2.0
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900