401 error when posting with jquery client

    General discussion

  • We have set up a JSON endpoint to our DomainService and are having problems calling the SubmitChanges operation from JQuery - we can call it without problem from c# test code.

    The web app is set up for integrated windows authentication.

    The c# test code generates the following HTTP request which works fine - in fiddler the Raw request looks like this:

    POST HTTP/1.1
    Connection: Keep-Alive
    Content-Type: application/json
    Content-Length: 247

    When I call from JQuery the Raw HTTP request in fiddler looks like this:

    POST HTTP/1.1
    Connection: keep-alive
    Content-Type: application/json
    Content-Length: 201
    X-Requested-With: XMLHttpRequest
    User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7
    Accept: application/json, text/javascript, */*; q=0.01
    Accept-Encoding: gzip,deflate,sdch
    Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3


    A 401 response is sent back to browser. I enter valid credentials but it always returns 401.1.

    the javascript code looks like this:

    var ajaxParameters = {
    type: "POST",
    dataType: "json",data: JSON.stringify({ "changeSet": [ ... ),
    contentType: "application/json",
    url: "",
    success: onPostSuccess,
    error: onError

    The crazy thing is - the DomainService method is correctly called and when I debug, the http response status is 200. I just don't know where the 401 status gets set and why.

    Can anyone help?

    Friday, January 13, 2012 7:24 AM

All replies

  • If you are "debugging" using the WebDev (Cassini) server built-in, there are a lot of things it doesn't do that IIS does.

    All kinds of permissions checking, etc.

    I'm guessing that the user under which the database access is being done doesn't have permissions.  Check what user is being used in IIS.  And there are all kinds of other dependencies to worry about too.  Like whether you are using Domain authentication for accessing the database server, etc. etc.

    Friday, January 13, 2012 8:45 AM
  • I'm not doing any database access, and I'm testing with IIS 7.5.

    Friday, January 13, 2012 9:22 AM
  • I learnt a little more about the problem.

    The 'CRIAMyRatingItem' class which is passed to the SubmitChanges operation has a DateTime field. We were not setting this field in the JSON, which led to 401 being returned even though the method on the server is called and runs successfully. I don't know where 401 gets set.

    Even though this DateTime field is not part of the [Key] it seems it is still important to set it to a valid value - so I assume there is something special regarding DateTime fields in the classes used in WCF-RIA operations. Can anyone confirm this?

    Update: same problem?

    Monday, January 16, 2012 4:39 AM