I am trying to do something that, in my opinion, will be simple. I need to create a WCF service that I can send through jQuery. I have an operation in my WCF service that is defined as follows:
[OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat=WebMessageFormat.Json, ResponseFormat=WebMessageFormat.Json)] public string SendMessage(string message, int urgency) { try {
Then I try to access this operation from an ASP.NET page through jQuery. My jQuery code to access this operation is as follows:
function sendMessage(message) { $.ajax({ url: "/resources/services/myService.svc/SendMessage", type: "POST", contentType: "application/json; charset=utf-8", data: ({ message: message, urgency: '1' }), dataType: "json", success: function (data) { alert("here!"); }, error: function (req, msg, obj) { alert("error: " + req.responseText); } }); }
When I execute this script, the error handler is disabled. An error message appears in it:
"An unexpected character 'c' was detected."
This message is included in a long stack trace. My question is: what am I doing wrong? I got other messages like this one ( How to send an array of complex objects with JSON, jQuery to ASP.NET MVC Controller? ) With no luck. How do I get this basic interaction?
Thanks!
jquery wcf
Villager
source share