In Visual Studio 2010 I created a new Ajax enabled WCF Service
[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";
}
In the Home Controllers Index.aspx view I add the jQuery:
function 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: <b>" + msg.d + "</b>";
}
})
}
function jqueryError(request, status, error) {
alert(request.responseText + " " + status + " " + error);
}
(using the built-in Web Server in VS 2010)
When I call DoWork, it works fine. When I call DoWork1 it always returns "error undefined" and the WCF call never happens.
I've tried every combination of: [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] I can think of and it does not help.
I must be missing something simple.
There are MANY posting about how to make this work, and other than the "no parameter" version, none have worked for me.
Can anyone post a sample MVC2 jQuery 1.4 .NET 4.0 WCF VS2010 working sample or spot the likely error?
Thanks.