asmx web service returning xml instead of json in .net 4.0

后端 未结 2 1925
独厮守ぢ
独厮守ぢ 2020-12-03 21:46

i have just upgraded a test copy of my site to asp.net 4.0 and have noticed a strange issue that only arises when i upload the site to my server.

the site has an asm

相关标签:
2条回答
  • 2020-12-03 22:27

    Are you sure .NET 4 is installed on your server?

    The ScriptHandlerFactory's "type" string in .NET 4 is:

    System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    

    ASP.NET 4 now includes that in its default web.config at the machine level. So, you shouldn't need any mapping to the ScriptHandlerFactory in your project's web.config, 3.5 or 4.

    0 讨论(0)
  • 2020-12-03 22:45

    well i managed to track it down by reading up about ajax web services requests are handled here...

    http://www.asp.net/%28S%28ywiyuluxr3qb2dfva1z5lgeg%29%29/learn/ajax/tutorial-05-cs.aspx

    basically a handler from asp.net 3.5 needs to be declared in your web.config handlers section under system.webserver so that it can return a JSON response instead of the default.

    here is what you need to add to the web.config handlers section (also add to httpHandlers section if you need to support IIS6)...

    <handlers>
       <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    

    i have my suspicions that this will need replacing with a .net 4.0 version of the same handler, but for now, it works.

    0 讨论(0)
提交回复
热议问题