加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 麻烦与ajax POST调用WCF服务

发布时间:2020-12-16 03:25:05 所属栏目:asp.Net 来源:网络整理
导读:我从ajax调用WCF服务,我可以让它作为GET请求而不是POST请求.所以: [OperationContract] [WebInvoke(Method = "GET",RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json)] public UserObject GetUser(string name) { // Add you
我从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",IsMobile = false };
        uo.fname = name;
        return uo;
    }

$.ajax({ //get user name and customer class
    type: "POST",success: function (data) { //get user name and customer class
        customerclass = data.d.custclass;
        ffname = data.d.fname;
    }
});

没有.我错过了一些简单的事吗?我在这里撕扯我的头发.谢谢

解决方法

使用

BodyStyle = WebMessageBodyStyle.WrappedRequest

for WebInvokeAttribute

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读