我正在从ajax调用WCF服务,我可以使其作为GET请求而不是POST请求工作。所以:

    [OperationContract]
    [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    public UserObject GetUser(string name)
    {
        // Add your operation implementation here
        var uo = new UserObject() { CustClass = "Guest", fname = "Chris", Email = "chris@Something", IsMobile = false };
        uo.fname = name;
        return uo;
    }




var json = { "name": "test" };
$.ajax({ //get user name and customer class
    type: "GET",
    url: "WritingAnalysisService.svc/GetUser",
    data: json,
    processData: true,
    contentType: "application/json",
    timeout: 10000,
    dataType: "json",
    cache: false,
    success: function (data) { //get user name and customer class
        customerclass = data.d.custclass;
        ffname = data.d.fname;
    }
});


可以,但是:

    [OperationContract]
    [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    public UserObject GetUser(string name)
    {
        // Add your operation implementation here
        var uo = new UserObject() { CustClass = "Guest", fname = "Chris", Email = "chris@Something", IsMobile = false };
        uo.fname = name;
        return uo;
    }




$.ajax({ //get user name and customer class
    type: "POST",
    url: "WritingAnalysisService.svc/GetUser",
    data: json,
    processData: true,
    contentType: "application/json",
    timeout: 10000,
    dataType: "json",
    cache: false,
    success: function (data) { //get user name and customer class
        customerclass = data.d.custclass;
        ffname = data.d.fname;
    }
});


不。我是否缺少简单的东西?我在这里扯头发。谢谢

最佳答案



BodyStyle = WebMessageBodyStyle.WrappedRequest


用于WebInvokeAttribute

07-26 01:52