How to get JSON response from a 3.5 asmx web service

后端 未结 4 1412
梦谈多话
梦谈多话 2020-11-27 07:03

I have the following method:

using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using         


        
4条回答
  •  半阙折子戏
    2020-11-27 07:09

    Just a doubt. When are you not getting a JSON response? Because when you invoke the web service from the client (I am assuming a web browser, i.e. xhr), you should specify the content type header on the request as "application/json; charset=yourcharset".

    I believe the above solution always returns json, no matter what the content type is specified from the client. The dotnet asmx framework allows this using the content-type header method, so the above could be classified as a hack, when a neat solution is available.

    Similar question at Return Json Data from ASMX web service

    This might help too -> http://forums.asp.net/p/1054378/2338982.aspx#2338982

    P.S: I am assuming you are using dotnet version 4.

提交回复
热议问题