0

I have a WCF service with an operationContract;

    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
    TrainLines GetLines();

Train lines is;

[DataContract]
public class TrainLines
{
    [DataMember]
    public List<string> Name { get; set; }
}

In the web config I have defined the binding as {basicHttpBinding}.

Now I am trying to consume that via jquery but I get the errors 200 and 400;

        jQuery.support.cors = true;

        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            url: "http:/Domain/WebService/GetLines",
            dataType: "json",
            success: function (msg) {
                ServiceSucceeded(msg);
            },
            error: ServiceFailed
        });
griegs
  • 22,624
  • 33
  • 128
  • 205
  • 200 errors? Aren't the 200 class HTTP responses successes? – M.Babcock Mar 13 '12 at 00:45
  • Then why do that get alerted in the error: callback function? – griegs Mar 13 '12 at 00:50
  • Can you show a fiddler trace? – M.Babcock Mar 13 '12 at 00:50
  • I'm getting code 0: Access is denied in jsFiddle – griegs Mar 13 '12 at 00:57
  • Are you using a fully qualified URL like what you have in your JS code snip? Javascript is bound by cross-domain limitations so if your service isn't in the same domain (or even running from the same server) as your JS then you will need to look at using technologies that support it. – M.Babcock Mar 13 '12 at 00:59
  • I am going cross domain but thought that jQuery.support.cors = true solved that – griegs Mar 13 '12 at 01:01
  • [Possibly related](http://stackoverflow.com/questions/7852225/is-it-safe-to-use-support-cors-true-in-jquery). It would be a security issue if they made it that easy for you. – M.Babcock Mar 13 '12 at 01:03
  • a 200 response just means a response was received. At that point, jQuery tries to parse the response, according to what you told it to expect (JSON). If the response is not json, for example if it is an XML document, or an HTML document, then jQuery will invoke the error handler with a parsererror. – Cheeso Mar 13 '12 at 03:30

0 Answers0