0

The company I am working for has asked me to create a web service in ASMX that accepts input as JSON and outputs the response as JSON.

How can I specify that a web method accepts JSON input?

I could achieve this by creating a web method with a string parameter and then deserializing the string myself (assuming that the string contains a JSON string)...

But what I want to know is this: is there a way to make the framework (ASMX) do this for me automatically?

[WebMethod]
[System.Web.Script.Services.ScriptMethod(ResponseFormat
System.Web.Script.Services.ResponseFormat.Json)]
    public string method(Model model) {
       // automatically deserialise the model
    }
JRG
  • 210
  • 1
  • 10
  • I think there is no way to create automatically create json and manage response. You need to write specific for manage your data. – A.M. Patel Dec 28 '18 at 04:43
  • But, when I see stackoverflow entries like this one (https://stackoverflow.com/questions/5320802/post-json-data-to-asmx-webservice), it makes me think that it is possible. So how is he making the framework automatically deserialize the json string? – JRG Dec 28 '18 at 05:00
  • Yes, Above link is correct. You need to specify response type and specify which type you need to convert data like json, xml etc. – A.M. Patel Dec 28 '18 at 05:16
  • Asmx service accepts json or you send data in json string and convert your data in your specific format. – A.M. Patel Dec 28 '18 at 05:19
  • ok, how do you do the former? @A.M.Patel – JRG Jan 02 '19 at 02:16

0 Answers0