带参数的jQuery WCF服务MVC2 VS2010 .NET 4.0调用失败

在Visual Studio 2010中,我创建了一个新的启用Ajax的WCF服务

[ServiceContract(Namespace = "TestWCFAjax.Bridge")] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class Bridge { [OperationContract] public string DoWork() { return "jQuery WCF call without parameters from MVC2 works." ; } [OperationContract] public string DoWork1(string parm) { return parm + " jQuery WCF call with parameters from MVC2 fails"; } 

在Home Controllers Index.aspx视图中,我添加了jQuery:

函数CallWebMethod(){

 $.ajax( { type: "POST", contentType: "application/json; charset-utf-8", url: "http://localhost:1452/Bridge.svc/DoWork1", dataType: "json", data: '{"parm":"test"}', error: jqueryError, success: function (msg) { alert("back"); var divForResult = document.getElementById("test"); divForResult.innerHTML = "Result: " + msg.d + ""; } }) } function jqueryError(request, status, error) { alert(request.responseText + " " + status + " " + error); } 

(使用VS 2010中的内置Web服务器)

当我打电话给DoWork时,它运行正常。 当我调用DoWork1时,它总是返回“错误未定义”并且WCF调用永远不会发生。

我已经尝试了以下各种组合:[WebInvoke(Method =“POST”,BodyStyle = WebMessageBodyStyle.WrappedRequest,ResponseFormat = WebMessageFormat.Json,RequestFormat = WebMessageFormat.Json)]我能想到它并没有帮助。

我一定很遗憾。

有很多关于如何使这项工作的post,除了“无参数”版本,没有一个对我有用。

任何人都可以发布样本MVC2 jQuery 1.4 .NET 4.0 WCF VS2010工作样本或发现可能的错误?

谢谢。

contentType:“application / json; charset-utf-8”,

应该

contentType:“application / json; charset = utf-8”,

我一直在编写和介绍如何在WCF中使用jQuery 。 整个MVC并不重要,或者至少不应该重要:)我有几个关于使用它的post,并且有一个链接供您从我的演示项目下载最新的源代码。