通过Ajax使用参数webservice调用GET

时间:2014-10-20 13:55:24

标签: asp.net ajax vb.net web-services

我正在尝试通过ajax调用GET webservice,找到了服务,但是我无法设置传递参数,引用的所有组合和JSON.stringify我用Google搜索并尝试失败,这些是我的尝试(在注释行中,您会看到我尝试的data参数格式:

$.ajax({ type: "GET", url: "webservice/srv_documento.asmx/FijarOrientacionEncabezado", //data: JSON.stringify({ IdElementoDoc: parseInt(id_elto), OrientacionVertical: Boolean(texto_vertical) }), //data: { IdElementoDoc: parseInt(id_elto), OrientacionVertical: 0 }, data: JSON.stringify('{ "IdElementoDoc": "1", "OrientacionVertical": "0" }'), //data: JSON.stringify({ IdElementoDoc: '"' + id_elto + '"', OrientacionVertical: '"' + texto_vertical + '"' }), contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { console.log("Ok " + dump(msg)); }, error: function (msg) { console.log("Error " + dump(msg)); } });

我收到消息缺少参数IdElementoDoc

  

{“Message”:“Llamada al servicio webnoválida.Faltaun valor paraelparámetro:\ u0027IdElementoDoc \ u0027。”,“StackTrace”:“en System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target ,IDictionary 2 parameters)\r\n en System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary 2个参数)\ r \ n en System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context,WebServiceMethodData methodData,IDictionary`2 rawParams)\ r \ n en System.Web.Script.Services .RestHandler.ExecuteWebServiceCall(HttpContext context,WebServiceMethodData methodData)“,”ExceptionType“:”System.InvalidOperationException“}”

这是我的服务定义(VB):

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
Public Function FijarOrientacionEncabezado(IdElementoDoc As Integer, OrientacionVertical As Integer) As String
    Try
        Dim log As New Logger

        log.log(String.Format("FijarOrientacionEncabezado {0}", IdElementoDoc))


        Return New JSONResponse(True, "ok").serialize()
    Catch ex As Exception
        Return New JSONResponse(False, ex.Message).serialize()
    End Try

End Function

0 个答案:

没有答案