Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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; } 
like image 827
Ben McCormack Avatar asked Apr 29 '10 14:04

Ben McCormack


People also ask

Should JSON be case sensitive?

JSON is case-sensitive. SQL is case-insensitive, but names in SQL code are implicitly uppercase.

Does case matter in JSON?

SQL, by default, is case insensitive to identifiers and keywords, but case sensitive to data. JSON is case sensitive to both field names and data.

What is a string JSON?

A JSON string contains either an array of values, or an object (an associative array of name/value pairs). An array is surrounded by square brackets, [ and ] , and contains a comma-separated list of values. An object is surrounded by curly brackets, { and } , and contains a comma-separated list of name/value pairs.


1 Answers

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.

like image 66
Serapth Avatar answered Oct 31 '22 03:10

Serapth