参数没有传递给webmethod [英] parameter not passing to webmethod
本文介绍了参数没有传递给webmethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI,
我需要将参数'999999999'传递给web服务,当我执行iam时收到错误System.InvalidOperationException:缺少参数:callerid。
请帮帮我。
I need to pass the parameter '999999999' to an webservice when i execute iam getting the error System.InvalidOperationException: Missing parameter: callerid.
pls help me out.
function SearchText() {
$('#<%= txtusername.ClientID%>').autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../HttpHandler/Autocomplete.asmx/GetCallername",
data: "{'callerid':'" +9999999999+ "'}",
dataType: "json",
success: function (data) {
response(data.d);
alert('i enter');
},
error: function (result) {
alert("Error");
}
});
}
});
}
webservice:
webservice :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using MSDataAccess;
using System.Data;
namespace Sun.HttpHandler
{
/// <summary>
/// Summary description for Autocomplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Autocomplete : System.Web.Services.WebService
{
[WebMethod]
public string GetCallername(string callerid)
{
ConnectionCls clsConObj = new ConnectionCls();
DataSet ds = null;
string strPriorityOfCall = null;
object[] obj = new object[6];
obj[0] = 1;
obj[1] = 1;
obj[2] = 1;
obj[3] = 1;
obj[4] = 1;
obj[5] = callerid;
ds = DataAccess.ExecuteDataset(clsConObj.getConnectionString(), "sp_autoload", obj);
if (ds.Tables[0].Rows[0]["CallerName"].ToString() != System.DBNull.Value.ToString())
{
return ds.Tables[0].Rows[0]["CallerName"].ToString();
}
else
{
return "User Doesnt Exist";
}
}
}
}
推荐答案
(' #<%= txtusername.ClientID%>')。autocomplete({
source: function (请求,响应){
('#<%= txtusername.ClientID%>').autocomplete({ source: function (request, response) {
.ajax({
type: POST,
contentType: application / json; charset = utf-8,
url: .. /HttpHandler/Autocomplete.asmx/GetCallername,
data: {'callerid': ' +9999999999+ '},
dataType:跨度> <跨度class =code-string> json,
成功: function (数据){
response(data.d) ;
alert(' 我输入');
},
错误: function (结果){
alert( 错误);
}
});
}
});
}
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "../HttpHandler/Autocomplete.asmx/GetCallername", data: "{'callerid':'" +9999999999+ "'}", dataType: "json", success: function (data) { response(data.d); alert('i enter'); }, error: function (result) { alert("Error"); } }); } }); }
webservice:
webservice :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using MSDataAccess;
using System.Data;
namespace Sun.HttpHandler
{
/// <summary>
/// Summary description for Autocomplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Autocomplete : System.Web.Services.WebService
{
[WebMethod]
public string GetCallername(string callerid)
{
ConnectionCls clsConObj = new ConnectionCls();
DataSet ds = null;
string strPriorityOfCall = null;
object[] obj = new object[6];
obj[0] = 1;
obj[1] = 1;
obj[2] = 1;
obj[3] = 1;
obj[4] = 1;
obj[5] = callerid;
ds = DataAccess.ExecuteDataset(clsConObj.getConnectionString(), "sp_autoload", obj);
if (ds.Tables[0].Rows[0]["CallerName"].ToString() != System.DBNull.Value.ToString())
{
return ds.Tables[0].Rows[0]["CallerName"].ToString();
}
else
{
return "User Doesnt Exist";
}
}
}
}
从报价中取出99999999。你基本上是添加数字加上字符串。由于它只是一个硬编码的数字,它是这样的:
Take the 99999999 out of the quotes. You essentially are adding the number plus the string. Since it is just a hard coded number do it like this:
data: "{'callerid':'9999999999'}",
这篇关于参数没有传递给webmethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文