如何获取WCF Restful Service的ref或out参数? [英] How to get the ref or out parameter of WCF Restful Service?
本文介绍了如何获取WCF Restful Service的ref或out参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个WCF Restful Service,如下所示:
I have a WCF Restful Service, like below:
[OperationContract]
[WebInvoke(Method ="POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat =WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json, UriTemplate = "CPSendInfo")]
int COSendTubeInfo(List<CPTXInfo> LstData,out string ErrMsg);
我想通过我的方法获得ErrMsg.怎么办?
I want get the ErrMsg by my method. How to do?
谢谢.有人可以尽快给我答复吗?
Thanks. Can some one reply me as soon as possible?
最紧急!!!
再次感谢.
Vince
推荐答案
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,
爱德华
这篇关于如何获取WCF Restful Service的ref或out参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文