Skip to main content
added 188 characters in body
Source Link
user987654
  • 79
  • 1
  • 3
  • 9

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

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>

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

added 171 characters in body
Source Link
user987654
  • 79
  • 1
  • 3
  • 9

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>

I have .NET web service which supposed to return the result as JSON, but it returns it as XML? Here is my code.

[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<MyData> GetMyData(string dataFilter, string param) { if (dataFilter.ToLower() == "filterValue") return getData(param); return null; } 

And here is

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

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>

Source Link
user987654
  • 79
  • 1
  • 3
  • 9

.NET WebService returns XML instead of JSON

I have .NET web service which supposed to return the result as JSON, but it returns it as XML? Here is my code.

[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)] public List<MyData> GetMyData(string dataFilter, string param) { if (dataFilter.ToLower() == "filterValue") return getData(param); return null; } 

And here is

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