locked
Boolean query option parameter for service operation formatted into URI with wrong case RRS feed

  • Question

  • The data service client seems to be formatting boolean parameters in the wrong case when I use the CreateQuery method of the data service client to add boolean query option.

    Its generating a URI such as http://localhost:8009/MyDataService.svc/MyServiceOperation()?myBoolParam=True when the URI should be generate as http://localhost:8009/MyDataService.svc/MyServiceOperation()?myBoolParam=true

    My service operation works when I change to case to lower manually using internet explorer as a test tool.

    In addition, according to this article Data Type Literal Representations the value for boolean literal should be presented to the service in lowercase.

    Is there a work-around solution for this?
    Wednesday, February 17, 2010 8:16 PM

Answers

  • Hi,

    Thanks for reporting this, I can confirm that this is not a desirable behavior. (And it doesn't matter which language you use). The workaround would be to use the approach suggested by Dave above (that is something like mybool ? "true" : "false").

    Thanks,
    Vitek Karas [MSFT]
    • Marked as answer by Sam Changtum Friday, February 19, 2010 6:34 PM
    Friday, February 19, 2010 9:06 AM
    Moderator

All replies

  • It's a VB.net only problem.

    I raised it here but never got a reply.  Workaround is there too.

    Dave

    Thursday, February 18, 2010 1:59 PM
  • I am experiencing this with C#.

    My first suspicion is the data service client has a bug in it where the URI is built-up into a string.

    I have resulted to using the BeginExecute method of the data service client in order to call my service operation and build-up my own URI.

    I too also pondered the idea of changing a boolean value to a lower case string before adding it as a parameter but then figured that wouldn't work because the data service client likes to wrap paraneters of the string type with single quotes when using AddQueryOption method.

    Dave, that's a good question - when you converted your boolean parameters to a string before adding it as a query option, does the data service client present your parameter value to the service wrapped in single quotes? If so, does your service operation still end up being called?

    Thursday, February 18, 2010 5:50 PM
  • Weird.  I assumed it was because if I display a boolen in VB.net I get "True" or "False", whereas in C# you get "true" or "false".

    It's a service operation, so you have to build your own URI don't you?  At least you did when I was coding it - there was no client-side discovery available for Service Operations.  As you're building your own URI you can just use a lower-cased value in the URI string instead of the vb-generated value of "True" or "False" which is created when VB implicitly converts the boolean to a string.

    Once I built my URI with "true" or "false", everything works fine - the parameter is resolved to a boolean correctly within the service operation.

    Dave
    Thursday, February 18, 2010 6:27 PM
  • I was hoping to take a boolean value and convert it to a lowercase string first before using the AddQueryOption method. Conclusion? It results in an HTTP response of 404 - Bad Request.

    Here's what the data service client assembled for a URI: http://localhost:8009/MyDataService.svc/MyServiceOperation()?myBoolParam='true'

    This make sense because the data service client treats all query options of the string type as character literals and thus wraps them in single quotes.

    My only option is to use the BeginExecute method of the DataServiceContext class and just build up my own URI.

    I am on the verge of reporting this as a bug.
    Friday, February 19, 2010 1:13 AM
  • Hi,

    Thanks for reporting this, I can confirm that this is not a desirable behavior. (And it doesn't matter which language you use). The workaround would be to use the approach suggested by Dave above (that is something like mybool ? "true" : "false").

    Thanks,
    Vitek Karas [MSFT]
    • Marked as answer by Sam Changtum Friday, February 19, 2010 6:34 PM
    Friday, February 19, 2010 9:06 AM
    Moderator
  • Today , the client library doesnt Literal encode the values passed into AddQueryOption API . When we write the values in the URI , we just call ToString on the values passed in and append that . As a result , what you see is expected behavior.

    You can vote on adding automatic Data Literal Encoding in the client library here :

    https://connect.microsoft.com/data/SearchResults.aspx?SearchQuery=WCF%20Data%20Services&wa=wsignin1.0
    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Friday, February 19, 2010 10:46 PM
    Moderator