在.NET 4.0中ASMX Web服务返回XML而不是JSON [英] asmx web service returning xml instead of json in .net 4.0

查看:145
本文介绍了在.NET 4.0中ASMX Web服务返回XML而不是JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚升级我的网站测试复印以ASP.NET 4.0,并已注意到一个奇怪的问题,只有当我的网站上传到我的服务器就出现了。

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.

该网站有一个返回JSON的ASMX Web服务,但是当我在我的服务器上运行的网站返回的XML。它作为已经在asp.net 3.5一年多工作的罚款。

the site has an asmx web service that returns json, yet when i run the site on my server it returns xml. it as been working fine in asp.net 3.5 for over a year.

将WebMethod装饰有正确的属性...

the webMethod is decorated with the correct attributes...

[WebMethod][ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<LocationRecentChange> RecentChanges()

和我的本地机器返回JSON。

and on my local machine it returns json.

但服务器(Windows 2008的64位)就可以返回XML。

yet on the server (Windows 2008 64bit) it returns xml.

使用Firebug控制台,您将看到一个200 OK响应和一堆XML,而我的本地机器上返回的数据是JSON我的期望。

using firebug console you will see a 200 OK response and a bunch of XML, and on my local machine the data returned is the JSON i expect.

下面是调用服务的JavaScript ..

Here is the javascript that calls the service..

function loadRecentData() {
$.ajax({
    type: "POST",
    url: "service/spots.asmx/RecentChanges",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: loadRecentUpdates,
    failure: function(msg) {
        //alert(msg);
    }
});

}

任何建议表示欢迎,这让我难倒了!

Any suggestions welcome, this has got me stumped!

推荐答案

您确定.NET 4安装在服务器上?

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

在.NET 4中的ScriptHandlerFactory的类型字符串是:

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现在包​​括在机器级其默认的web.config。所以,你不应该需要在项目的web.config,3.5或4任何映射到ScriptHandlerFactory。

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.

这篇关于在.NET 4.0中ASMX Web服务返回XML而不是JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆