开发者

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

开发者 https://www.devze.com 2022-12-28 20:17 出处:网络
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

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",开发者_如何学Python"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;
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号