I am trying to use the ASMX web service from javascript using jQuery. It works fine when I ask for XML, but I want to use .net JSON; (it also starts to bother me that this is not working)
Web Service Code:
using System; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Web.Script.Services; [WebService()] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] public class SimpleService : WebService { [WebMethod] public String GetString() { return "value"; } }
Customer Code:
$.ajax({ type: "POST", url: "SimpleService.asmx/GetString", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json" });
And the answer is ...
Content-Type: text/xml; charset=utf-8 Server: Microsoft-IIS/7.5 X-AspNet-Version: 2.0.50727 X-Powered-By: ASP.NET <?xml version="1.0" encoding="utf-8"?><string xmlns="http://tempuri.org/">value</string>
The query always succeeds, but jQuery gives me an analyzer error (which is not surprising given the answer).
I'm crazy. I tried adding the ServiceMethod attribute with the ResponseType parameter set to JSON, but nothing works.
I do not want to use the javascript.NET ScriptManager generator, so please do not suggest using them.
json web-services asmx asp.net-ajax
Evan Larkin Jan 30 2018-11-11T00: 00Z
source share