FromBody in WebService

和自甴很熟 提交于 2019-12-25 04:30:16

问题


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){}

but when i send the request in json it looks like that:

{
  "request":
  {
  "parameter1" : "param1",
  "parameter2" : "param12",
  }
}

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?


回答1:


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) { ... }

It then reads in the data as Content-Type: application/json in the form

{
  guid: #,
  name: "",
  ... 
}


来源:https://stackoverflow.com/questions/42765459/frombody-in-webservice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!