Web service returning XML instead of JSON

I’m designing a web service (asmx) using the .NET framework 3.5 on an MVC site with the requirement to return JSON. Using some basic tutorials and the templates Visual Studio provides i was able to get a working model running on my laptop. When I deployed the solution to the server the results came back as XML.

I found the solution here. Since I am using .NET 3.5 for my web service, the handlers for the asmx  are not included in the machine.config. Adding the following line under system.webServer fixed this issue.

<code>&lt;system.webServer&gt;
    &lt;handlers&gt;
        &lt;add name="ScriptHandlerFactory"
             verb="*" path="*.asmx"
             type="System.Web.Script.Services.ScriptHandlerFactory, 
                 System.Web.Extensions, Version=4.0.0.0, Culture=neutral, 
                 PublicKeyToken=31bf3856ad364e35"
             resourceType="Unspecified" /&gt;
    &lt;/handlers&gt;
&lt;/system.webServer&gt;</code>

(Views: 297)

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.