问题
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