Sunday 15 January 2012

c# - Webservice ignores ResponseFormat.Json -


I have a simple $ for my ASP.NET webservice. I have tried all possible solutions without any luck, am I missing something?

My jQuery code:

  $ Ajax ({type: "POST", url: "/ services / Configrr service /. ContentType:" application / json; charset = utf-8 ", data:" {} ", data type:" Jason ", success: function (Data, textstate, jk xhr) {if (data! = Null) {warning (data. D);} other {warning ("data undefined: |" + "+" + jqXhr + "|" + "text position);} }, Error: Function (JK XHR, TextStatus, Error Trouwer) {Alert (Jake Xhr + "" + + TextStats + "|" + Error appears;)}});   

My asmx.cs code:

  [Vebmth (Description = "The initial configuration values ​​for Configretr")] [ScriptMethod (ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)] Public ConfiguratorModel GetInitialModel () {Return new item} {title: "10 units", text: "item text ..."}; } Public Square Items {Public String Title} {Received; Set;} public string text {get; Setup;}}   

Update 1: In my solution, I'm getting a feedback back, but only in the form of XML I have tried to reproduce the error in a new solution, with no fate, everything works well in both old and new solutions. The only difference that Asmsx services actually return the same response is that one of them fails with jquery error: parsererror, unexpected token & lt;

Update 2: The response header in my old solution is always "text / xml; charset = utf-8"

Update 3: My Web Configure all the entries which are required to respond to "Text / XML; Charset = UTF-8" why?

One of my colleagues helped me, pointing in the direction. I came to know that the handler was asp net 2.0. The solution was upgraded from 2.0 to 4.0 in the beginning of this year. All I had to do was:

  & lt; add name = "WebServiceHandlerFactory- integrated" path = "*. Asmx" verb = "GET, HEAD, POST, DEBUG" type = "system .WebServices.Protocols.WebServiceHadlerFactory, System.Web.Services, Version = 2.0.0.0, Culture = neutral, Sarwajnikkitokn = B03f5f7flld50a3a "module =" Manditpeeplainhandlr "Skriptprosesr =" "Snsadnprkar =" unspecified "requireAccess =" script "allowPathInfo =" false "Preekandisn =" integrated mode "Pratisadbfr limit =" 4194304 "/>  < / Pre> 

with:

  & lt; Add name = "Vebsaisewahandlrfitr-integrated -4.0" path = "*. Get Asmx" action = "head, post, DEBUG" type = "System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version = 4.0.0.0, Culture = Neutral, Public KeyConnect = 31bf3856ad364e35 "preCondition =" Integrated Mode, Runtime Versionv4.0 "/>   

The good idea is to try removing all the handlers temporarily, only:

  & lt; Add name = "ScriptResource" preCondition = "integratedMode" action = "GET, HEAD" path = "ScriptResource.axd" type = "System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version = 4.0.0.0, Culture = Neutral, PublicKeyToken = 31BF3856AD364E35 "/>    

No comments:

Post a Comment