Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello,
bellow is my web service code. Not working..!
I going to pass JSON String to it.
please tell me is it correct?

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
    //[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
    public string updateUserInfo2(string inputdata)
    {
        string json="";
        DataTable tblUsers=null;

        var jsonResult = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(inputdata);
        string UserAutoId = jsonResult["UserAutoId"];
        string userId = jsonResult["userId"];
        string fname = jsonResult["fname"];
        string lname = jsonResult["lname"];
        string email = jsonResult["email"];       
        string hieght = jsonResult["hieght"];

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);

        con.Open();
        SqlDataAdapter da = new SqlDataAdapter("UpdateUserInfo2 ", con);
        da.SelectCommand.CommandType = CommandType.StoredProcedure;
        da.SelectCommand.Parameters.Add("@UserAutoId", SqlDbType.VarChar).Value = UserAutoId;
        da.SelectCommand.Parameters.Add("@userId", SqlDbType.VarChar).Value = userId;
        da.SelectCommand.Parameters.Add("@firstName", SqlDbType.VarChar).Value = fname;
        da.SelectCommand.Parameters.Add("@lastName", SqlDbType.VarChar).Value = lname;
        da.SelectCommand.Parameters.Add("@emailadr", SqlDbType.VarChar).Value = email;       
        da.SelectCommand.Parameters.Add("@hieght", SqlDbType.VarChar).Value = hieght;
        da.SelectCommand.Parameters.Add("@retValue", System.Data.SqlDbType.Int).Direction = System.Data.ParameterDirection.ReturnValue;
        da.Fill(tblUsers);

        int retval = (int)da.SelectCommand.Parameters["@retValue"].Value;
        if (retval == 1)
        {
            //string result = "1";
            //json = new JavaScriptSerializer().Serialize(result);
            json = DataTableToJSONWithJavaScriptSerializer(tblUsers);
        }
        else if (retval == 2)
        {
            string result = "2";
            json = new JavaScriptSerializer().Serialize(result);
        }
        con.Close();
        return json;
    }


What I have tried:

I am trying to call web service using ExtJS.


Below is Ext JS Code.
var data = {};

                        data.inputdata = {
                            UserAutoId: UserAutoId,
                            userId: UserId,
                            fname: fName,
                            lname: lName,
                            email: email,
                            hieght: hieght
                        };
                       
                       
                        var x = Ext.encode(data.inputdata);
                       
                        console.log(x);

                        Ext.Ajax.request({
                            url: 'WebService.asmx/updateUserInfo2',
                            method: 'POST',
                            headers: { 'Content-Type': 'application/json' },
                            jsonData: { inputdata:x },
                            scope: this,

                            success: function (response) {
                                var mydata = Ext.decode(response.responseText);
                                console.log(mydata);

                            }
Posted
Updated 6-Jan-17 19:52pm

1 solution

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
    //[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
    public static string updateUserInfo2(string inputdata)

One explanation for static Why webmethod have to be static in asp.net (C#)[^]
 
Share this answer
 

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