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

查看:38
本文介绍了asmx Web 服务在 .net 4.0 中返回 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.

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

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