When is case sensitivity important in JSON requests to ASP.NET web services (ASMX)?

54,989

According to JSON-RPC spec, the answer is always.

9.0 Case-Sensitivity of Procedure and Parameter Names

Conforming implementations MUST treat procedure and parameter names as being case-sensitive such the names bar and BAR would be seen as two distinct entities.

So, it sounds like the situations when it worked for you were the exceptions, not the cases where they didn't. Chances are someone on some side of the equation was just not adhering to the specs.

Share:
54,989
Ben McCormack
Author by

Ben McCormack

Becoming a better version of myself. Website: http://benmccormack.com Twitter: @bmccormack I find great satisfaction in developing solutions that make it easier and simpler for people to do their jobs. I haven't updated by Stack Overflow CV in forever, so check out my LinkedIn page.

Updated on July 28, 2022

Comments

  • Ben McCormack
    Ben McCormack almost 2 years

    I've done the following tests with JSON requests sent to an ASP.NET 2.0 ASMX web service (using AJAX Extensions 1.0 for ASP.NET 2.0) and it seems that case sensitivity is important in some situations but not in others. See the following examples:

    • Case matches 100%:

      {"request":{"Address":{"Address1":"123 Main Street","Address2":"suite 20","City":"New York","State":"NY","Zip":"10000","AddressClassification":null}}}
      

      Result: HTTP/1.1 200 OK

    • Case of contained object name Address does not match:

      {"request":{"address":{"Address1":"123 Main Street","Address2":"suite 20","City":"New York","State":"NY","Zip":"10000","AddressClassification":null}}}
      

      Result: HTTP/1.1 200 OK

    • Case of web service parameter request does not match:

      {"Request":{"address":{"Address1":"123 Main Street","Address2":"suite 20","City":"New York","State":"NY","Zip":"10000","AddressClassification":null}}}
      

      Result: HTTP/1.1 500 Internal Server Error

    (Quick note: The fact that the class Request and the parameter request share the same name is not relavant. Even if I change the parameter name to lrequest, case sensitivity is still required.)

    When is case sensitivity in JSON Web Service requests important? Also, is this a general web service issue or is this specific to ASP.NET AJAX?


    Additional background information:

    I'm using the AJAX Extensions 1.0 for ASP.NET 2.0, so this may have been addressed in later versions of the framework. If so please let me know.

    After following up to the answers in my most recent question regarding formatting JSON strings, I realized that the reason my request was failing wasn't because of invalid JSON (thanks to T.J. Crowder for pointing that out and linking to http://www.jsonlint.com/ for JSON validation). Rather, after doing some more testing, I learned that the problem was because the web service didn't how my JSON object was formatted and I discovered the web service was very picky in regards to case sensitivity. It seems that sometimes case sensitivity is important, whereas other times it is not (see examples above).

    Here's what my C# code for the web method and classes looks like:

    [WebMethod]
    public Response ValidateAddress(Request request)
    {
        return new test_AddressValidation().GenerateResponse(
            test_AddressValidation.ResponseType.Ambiguous);
    }
    
    ...
    
    public class Request
    {
        public Address Address;
    }
    
    public class Address
    {
        public string Address1;
        public string Address2;
        public string City;
        public string State;
        public string Zip;
        public AddressClassification AddressClassification;
    }
    
    public class AddressClassification
    {
        public int Code;
        public string Description;
    }