I have .NET web service which supposed to return the result as JSON, but it returns it as XML? Here is my code.
[WebService(Namespace = "http://tempuri.org/MyService")] [ScriptService] public class MyService : System.Web.Services.WebService { [WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<MyData> GetMyData(string dataFilter, string param) { if (dataFilter.ToLower() == "filterValue") return getData(param); return null; } } public class MyData { public string id { get; set; } public string name { get; set; } protected internal MyData() { } } And here is the web.config
<system.web> <compilation debug="true" targetFramework="4.0"/> <httpRuntime/> <customErrors mode="Off"/> <webServices> <protocols> <add name="HttpGet"/> <add name="HttpPost"/> </protocols> </webServices> <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/> </system.web>
EDIT The web service is working fine only when passing digits in the parameters but it returns internal server error when passing characters inside the parameters. I got confused :O