且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取WCF Restful Service的ref或out参数?

更新时间:2023-11-07 21:40:22

Vince,

Hi Vince,

您想得到Ajax的回复吗?如果尝试使用Fiddler或PostMan发送请求,则会收到如下所示的响应,并且可以检索json对象.

Did you want to get response from Ajax? If you try Fiddler or PostMan to send request, you will get response like below, and you could retrieve the json object.

{
  "COSendTubeInfoResult": 123,
  "ErrMsg": "Error"
}

这是一个简单的演示,可让Ajax获得响应.

Here is a simple demo for getting response by Ajax.

//WCF Rest Service
//IService
        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json,
           ResponseFormat = WebMessageFormat.Json, UriTemplate = "CPSendInfo")]
        int COSendTubeInfo(int LstData, out string ErrMsg);
//Service
        public int COSendTubeInfo(int LstData, out string ErrMsg)            
        {
            ErrMsg = "Error";
            return 123;
        }

//Ajax Request


(function(){ var p = {"LstData":123};
(function () { var p = { "LstData": 123 };


.ajax({ 类型:"POST", contentType:"application/json; charset = utf-8", 网址:"http://localhost:39668/RestService.svc/CPSendInfo", 数据:JSON.stringify(p), 数据类型:"json", 成功:功能(数据){ console.log(data.COSendTubeInfoResult); console.log(data.ErrMsg); }, 错误:函数(结果){ 警报(结果); } }); });
.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: 'http://localhost:39668/RestService.svc/CPSendInfo', data: JSON.stringify(p), datatype:'json', success: function (data) { console.log(data.COSendTubeInfoResult); console.log(data.ErrMsg); }, error: function (result) { alert(result); } }); });

***的问候,

Best Regards,

爱德华