使用JSON将数据传递到ASP.NET Web服务

使用JSON将数据传递到ASP.NET Web服务,asp.net,vb.net,json,web-services,Asp.net,Vb.net,Json,Web Services,我已经成功地以JSON格式(使用不需要参数的服务方法)从ASP.NETWebService返回了数据,但是在进行需要参数的webservice调用时遇到了困难 网络服务: <WebMethod()> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _ Public Function TestWebService(ByVal Description As String) As S

我已经成功地以JSON格式(使用不需要参数的服务方法)从ASP.NETWebService返回了数据,但是在进行需要参数的webservice调用时遇到了困难

网络服务:

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
Public Function TestWebService(ByVal Description As String) As Stock
    Dim res As New Stock(Guid.NewGuid, Description)
    Return res
End Function
Javascript:

client = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
client.onreadystatechange = DataReturnedFromHttpRequest;
client.open("GET", "/MyWebService.asmx/TestWebService?" + JSON.stringify({"Description":["Test"]}), true); 
client.setRequestHeader("Content-Type", "application/json");
client.send(null);
答复:

{
  "Message": "Invalid web service call, missing value for parameter: \u0027Description\u0027.",
  "StackTrace": "   at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n   at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\r\n   at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n   at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)",
  "ExceptionType": "System.InvalidOperationException"
}

我理解错误,但似乎无法正确设置请求格式。终于得到了。。。因此,对于任何好奇的人来说,答案都是琐碎的

get请求必须采用以下格式

/MyWebService.asmx/MyWebserviceMethod?Param1=%22ParamValue1%22&Param2=%22ParamValue2
那么它就像一个符咒。

/MyWebService.asmx/MyWebserviceMethod?Param1=%22ParamValue1%22&Param2=%22ParamValue2