Note that there are some explanatory texts on larger screens.

plurals
  1. PO400 Bad request when trying to contact WCF service using XHR
    primarykey
    data
    text
    <p>I'm making a WCF web service that will return a json object, but I keep getting a 400 bad request error when I try to make an AJAX call:</p> <pre><code>OPTIONS http://localhost:55658/WebServiceWrapper.svc/GetData?_=1318567254842&amp;value=97 HTTP/1.1 Host: localhost:55658 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 DNT: 1 Connection: keep-alive Origin: http://localhost:3000 Access-Control-Request-Method: GET Access-Control-Request-Headers: content-type HTTP/1.1 400 Bad Request Server: ASP.NET Development Server/10.0.0.0 Date: Fri, 14 Oct 2011 04:40:55 GMT X-AspNet-Version: 4.0.30319 Cache-Control: private Content-Length: 0 Connection: Close </code></pre> <p>Here is my AJAX call:</p> <pre><code>$.ajax({ contentType: 'application/json', url: 'http://localhost:55658/WebServiceWrapper.svc/GetData', dataType: 'json', data: { value: 97 }, success: function (data) { alert('success' + data); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert('failure' + errorThrown); } }); </code></pre> <p>Here is my WCF service definition:</p> <pre><code>public class WebServiceWrapper : IWebServiceWrapper { public object GetData(int value) { return new { ReturnValue = string.Format("You entered: {0}", value) }; } } </code></pre> <p>And it's interface:</p> <pre><code>[ServiceContract] public interface IWebServiceWrapper { [OperationContract] object GetData(int value); } </code></pre> <p>I know I've solved this problem before, but I can't remember what I had done before. Any help would be greatly appreciated as the hole I'm putting in the wall is just getting bigger and bigger.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload