Web服务方法不能调用..! [英] Web service method not call..!
本文介绍了Web服务方法不能调用..!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
贝娄是我的网络服务代码。不工作..!
我要把JSON字符串传递给它。
请告诉我它是否正确?
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;
}
我的尝试:
我正在尝试使用ExtJS调用Web服务。
以下是Ext JS Code。
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);
}
推荐答案
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
//[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public static string updateUserInfo2(string inputdata)
st的一个解释atic 为什么web方法必须在asp中保持静态。 net(C#) [ ^ ]
这篇关于Web服务方法不能调用..!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文