WebService 中的 FromBody [英] FromBody in WebService
问题描述
我正在制作 WebService(.asmx) 并且我想在 WebApi 中使用某种属性,例如 [FromBody].例如我有网络服务方法:
I am making WebService(.asmx) and I want to use some kind of attribute like [FromBody] in WebApi. For example I have web service method:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
public virtual ServiceResponse GetTest(Test request){}
但是当我在 json 中发送请求时,它看起来像这样:
but when i send the request in json it looks like that:
{
"request":
{
"parameter1" : "param1",
"parameter2" : "param12",
}
}
我希望 json 请求没有请求".但是当我删除它时,我得到异常:无效的 Web 服务调用,缺少参数值:请求".我如何才能在 Web 服务中实现这一点?
I want the json request to be without "request".But when i remove it i get exception: Invalid web service call, missing value for parameter: 'request'. How can I achieve that in Web Services?
推荐答案
以下是我如何能够完成您正在尝试执行的操作的示例:
Here is an example of how I was able to do what you are trying to do:
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "save")]
public BaseResponse SaveSurvey(Survey survey) { ... }
然后以Content-Type: application/json
的形式读入数据
{
guid: #,
name: "",
...
}
这篇关于WebService 中的 FromBody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!