Posting from JQuery to WCF Service

Posted by Villager on Stack Overflow See other posts from Stack Overflow or by Villager
Published on 2010-03-20T02:05:16Z Indexed on 2010/03/20 2:11 UTC
Read the original article Hit count: 379

Filed under:
|

Hello,

I have a WCF Service (called "myservice.svc") that takes a message from a user and saves it to the database. It returns a response to the user in the form of a number. This operation looks like this:

[OperationContract]
[WebGet]
public string SubmitMessage(string message)
{
  try
  {
    // SAVE TO DATABASE
    return "1";
  }
  catch (Exception ex)
  {
    return "0";
  }
}

I want to call this operation from some JQuery. I'm using the approach shown here:

$.getJSON(
  "/services/myService.svc",
  {message:"some text"},
  function (data) {
    alert("success");                
  }
);

Oddly, the "success" alert is never displayed. In addition, I have set a breakpoint in my WCF service and it is never being tripped. What am I doing wrong?

Thank you

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about wcf