When upgrading your IIS7 Web Application to .NET 4.0, many people experience the “500.19 Service Unavailable” HTTP error response along with a more detailed “System.InvalidOperationException: Request format is invalid: application/json; charset=utf-8″ message when calling a .asmx WebService through jQuery AJAX (or other JSON-capable library).
This is most definitely due to an invalid *.asmx handler mapping in your web.config.
To fix this issue, look for the current *.asmx handler (search for “*.asmx” in web.config) and comment it out, like this:
<-- This row is commented out due to "Request format is invalid: application/json" error
<add name="WebServiceHandlerFactory-Integrated" path="*.asmx" verb="GET,HEAD,POST,DEBUG" type="System.Web.Services.Protocols.WebServiceHandlerFactory, System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" modules="ManagedPipelineHandler" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="integratedMode" responseBufferLimit="4194304" />
-->
(Note that the actual attributes may vary, like verb=”…” may just be an asterisk, like verb=”*”. So just look for *.asmx)
Above this line, insert the following lines:<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />That is all – now your AJAX handling (along with JSON serialization) should work just fine.
No comments:
Post a Comment