web service returns xml instead of json

Hi,

I am calling a web service (asmx) with jquery.

When I run my application on IIS 6 or IIS 7 all is good.

Yesterday I moved the application on IIS 7.5 (server 2008 R2) and the call returns xml instead of json no matter what.

The call is this:

 

   var WebServiceUrl = legacy + 'PopulateSmallCartMessage';
 
            var parameters = null;
 
            var res = null;
 
            $.ajax({
 
                type: "POST",
 
                contentType: "application/json; charset=utf-8",
 
                url: WebServiceUrl,
 
                data: parameters,
 
                datatype: "jsondata",
 
                async: true,
 
                success: function (result) {
 
                    $('#smallcartmessage').html(result.d);
 
                    $('.fbloader').hide();
 
                },
 
                error: function (request, status, error) {
                    alert(request.statusText + "/" + request.status + "/" + error);
                    $('.fbloader').hide();
                }
 
            });

The web service function is decorated only with the webmethod attribute.

I also added to the web config the following but I thing is not needed.

 

      <webServices>
          <protocols>
              <add name="HttpGet"/>
              <add name="HttpPost"/>
          </protocols>
      </webServices>

 

Any thoughts?

Do you have asp.net 3.5 ScriptHandlerFactory handler declared in your web.config handlers section under system.webserver?

<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"/>

p3tar

Do you have asp.net 3.5 ScriptHandlerFactory handler declared in your web.config handlers section under system.webserver?

<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"/>

 

No, do I need to? The app runs on .net 4 Inergrated app pool. It wasn’t there when the app was working fine.

If you change

datatype: "jsondata",

to

datatype: "json",

does it fix the problem?

Thanx for your help, it seems that there is a problem with the IIS settings hosting the project.

The administrator is looking in to it.

I would like to mark your post as answer but it might misleed others.

Kudos for your replies.

Hi, did you get this fixed?

same situation, iis 7.5, 4.0 asmx returning xml instead of json, funny thing is that it was working fine in our ii6 until we upgraded recently.

Any help will be appreciated.

 contentType: "application/json; charset=utf-8",
 dataType: "json",

Please check ajax method that dataType should be json

http://dotnetplace.com/post/Fill-ASPNETDropdownlist-through-JSON-data-using-jQuery.aspx


Leave a Reply