Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen is case sensitivity important in JSON requests to ASP.NET web services (ASMX)?
    primarykey
    data
    text
    <p>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:</p> <ul> <li><p>Case matches 100%:</p> <pre><code>{"request":{"Address":{"Address1":"123 Main Street","Address2":"suite 20","City":"New York","State":"NY","Zip":"10000","AddressClassification":null}}} </code></pre> <p>Result: <code>HTTP/1.1 200 OK</code></p></li> <li><p>Case of contained object name <code>Address</code> does not match:</p> <pre><code>{"request":{"address":{"Address1":"123 Main Street","Address2":"suite 20","City":"New York","State":"NY","Zip":"10000","AddressClassification":null}}} </code></pre> <p>Result: <code>HTTP/1.1 200 OK</code></p></li> <li><p>Case of web service parameter <code>request</code> does not match:</p> <pre><code>{"Request":{"address":{"Address1":"123 Main Street","Address2":"suite 20","City":"New York","State":"NY","Zip":"10000","AddressClassification":null}}} </code></pre> <p>Result: <strong><code>HTTP/1.1 500 Internal Server Error</code></strong></p></li> </ul> <p><em>(Quick note: The fact that the class <code>Request</code> and the parameter <code>request</code> share the same name is not relavant. Even if I change the parameter name to <code>lrequest</code>, case sensitivity is still required.)</em></p> <p><strong>When is case sensitivity in JSON Web Service requests important?</strong> Also, is this a general web service issue or is this specific to ASP.NET AJAX?</p> <hr> <p>Additional background information:</p> <p>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.</p> <p>After following up to the answers in my most recent <a href="https://stackoverflow.com/questions/2737525/how-do-i-build-a-json-object-to-send-to-an-ajax-webservice">question regarding formatting JSON strings</a>, I realized that the reason my request was failing wasn't because of invalid JSON (thanks to <a href="https://stackoverflow.com/users/157247/t-j-crowder">T.J. Crowder</a> for pointing that out and linking to <a href="http://www.jsonlint.com/" rel="nofollow noreferrer">http://www.jsonlint.com/</a> 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 <em>picky</em> in regards to case sensitivity. It seems that sometimes case sensitivity is important, whereas other times it is not (see examples above).</p> <p>Here's what my C# code for the web method and classes looks like:</p> <pre><code>[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; } </code></pre>
    singulars
    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