Hi all,
I have successfully returned data from a ASP.Net webservice in JSON format (using a service method that required no parameters) but have struggled with making a webservice call that requires a parameter.
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
Object:
Public Class Stock
Public Sub New()
End Sub
Public Sub New(ByVal StockID As Guid, ByVal Description As String)
Me._StockID = StockID
Me._Description = Description
End Sub
Public Property StockID As Guid
Public Property Description As String
End Class
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);
Response:
{"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"}
I understand the error but cant seem to work out how to format my request correctly.