locked
Backslash in query expression in LS2 with oData RRS feed

  • Question

  • Hi together,

    we just migrated a LS project to v2 and came across the following problem: A query to a service (attached to LS) fails, the query condition is 'IFB\i10600' (user name with domain). We get the error 'Bad Request - Error in query syntax' - during processing the backslash in the query is converted to a '/', so the complete service call is

    GET /ActiveDirectoryData.svc/Users('IFB/i10600') which fails with the above error.

    To make it clearer: The domain\username string is used as foreign key in several tables and then used in the service call.

    If I execute the query manually with ../Users('IFB%5Ci10600')  (backslash replaced with HTML equivalent) the query is execuded without error, BUT: How can I get the LS data service to do the same? (In LS1 this worked without problems.)
    Generally, LS2 treats these special characters correctly in it's oData calls, as far as I see in a simple test project; what's the difference with the service call here?

    Thanks and best regards

    Robert



    • Edited by robert-ndev Wednesday, August 22, 2012 10:08 AM
    Wednesday, August 22, 2012 9:48 AM

Answers

  • Hi Robert,

    I've been working with the team and we've confirmed this is a problem and logged a bug. Unfortunately there isn't an easy workaround. You have a couple options, one is -- don't use a backslash in the primary key. The other option is to write a custom WCF behavior for your service that intercepts the message and rewrites the query correctly. Here's a reference on how to create WCF behaviors: http://msdn.microsoft.com/en-us/magazine/cc163302.aspx

    We're sorry for the inconvenience.

    -Beth


    Senior Program Manager, Visual Studio Community http://msdn.com/lightswitch http://msdn.com/vbasic http://msdn.com/vsto http://www.bethmassi.com

    Monday, August 27, 2012 6:08 PM

All replies

  • Hi Robert

    Can you tell me a little bit more about your scenario? Are you connecting to an external OData service and then creating a modeled query to it through the designer?

    Thanks,
    -Beth


    Senior Program Manager, Visual Studio Community http://msdn.com/lightswitch http://msdn.com/vbasic http://msdn.com/vsto http://www.bethmassi.com

    Friday, August 24, 2012 9:22 PM
  • Hi Beth,

    yes, your assumption is correct, it's an external (but own) data service which provides user data from an Active Directory; this service is imported in LightSwitch as datasource and linked by virtual relationships to several data entities. As key for retrieving user data from the service a string in the form "DOMAIN\Username" is used (and stored as foreign key in the linked data entities).

    It seems, that a key in the mentioned format used as unique key parameter for a single-entity-query in the form "/ActiveDirectoryData.svc/Users('IFB/i10600')" is not formatted in a way that the backslash is converted to it's HTML equivalent if the query is created by the LS runtime.
    I hope this makes it clear?

    This problem appeared after migrating the solution (LS app and service) from LS1 to LS2; in LS1 it worked fine.

    Thanks for your support!

    Best Regards,
    Robert





    • Edited by robert-ndev Saturday, August 25, 2012 11:41 AM
    Saturday, August 25, 2012 11:05 AM
  • Would you not just simply HtmlEncode the username before constructing the URL?

    I'm definitely not a web application expert, so I may be way off base here.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    Sunday, August 26, 2012 12:40 PM
    Moderator
  • Hi Yann,

    the URL for the service call is created by LightSwitch as the service is called by a relation property, so there is no way for me to construct the URL - otherwise it would be a simple task...

    But thanks anyway!

    Best Regards, Robert

    Sunday, August 26, 2012 4:41 PM
  • Ah, no wonder it seemed such an "obvious" answer. Still, it sometimes pays to ask these types of questions. :-)

    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.

    Sunday, August 26, 2012 11:58 PM
    Moderator
  • Hi Robert,

    I've been working with the team and we've confirmed this is a problem and logged a bug. Unfortunately there isn't an easy workaround. You have a couple options, one is -- don't use a backslash in the primary key. The other option is to write a custom WCF behavior for your service that intercepts the message and rewrites the query correctly. Here's a reference on how to create WCF behaviors: http://msdn.microsoft.com/en-us/magazine/cc163302.aspx

    We're sorry for the inconvenience.

    -Beth


    Senior Program Manager, Visual Studio Community http://msdn.com/lightswitch http://msdn.com/vbasic http://msdn.com/vsto http://www.bethmassi.com

    Monday, August 27, 2012 6:08 PM
  • Hi Beth,

    thanks for investigating the issue; we'll find a workaround ;-) A custom WCF behaviour is an interesting approach; I'll give it a try.

    But a fix in a following service release of LightSwitch would be great!

    Best Regards
    Robert

    Tuesday, August 28, 2012 4:24 PM
  • Hi Beth / Robert,

    I have the same problem with Windows Authentication.
    We can add a user.

    If I try to add a role to that new user (domain\user) the error occurs. --> 'Bad Request - Error in query syntax'

    If I remove the "\" in (domain\user)  in UserName and lowerdUserName in the Intrinsic Database everything works fine.

    When will a fix be available ;-)



    • Edited by NorbertK Tuesday, October 16, 2012 2:18 PM
    Tuesday, October 16, 2012 1:59 PM
  • Hi Beth / Robert,

    We have the same problem with "\" and 'Bad Request - Error in query syntax'

    Fix would be very helpful.

    Thanks.

    Tuesday, October 30, 2012 10:11 AM
  • Hi Beth,

    Any chances this OData bug to be resolved?

    (I'm trying to build a single LightSwitch application to manage users in several other LightSwitch applications and cannot add role assignments, because the users' names are in format domain\user. Btw, I can register the users)

    Thx!

    Friday, May 16, 2014 12:45 PM
  • What version are you using? This should have been fixed in LS v3 that shipped with VS2012 Update 2. LightSwitch implemented a work around, but not sure if it was fixed in OData itself.

    Senior Program Manager, Visual Studio Community http://www.bethmassi.com http://msdn.com/lightswitch http://dev.office.com

    Monday, May 19, 2014 7:38 PM
  • Hello,

    I am running into the same issue; I have recently upgraded LS 2011 solution to VS2013. Can you confirm that it was fixed in VS2012 update 2? If not, please identify what update will have this fix?

    thanks so much!

    Thursday, January 29, 2015 2:05 PM
  •  I found a case closed by Microsoft 780577 that is related to this issue. It looks like it is fixed in HTMLClient but not Silverlight. Is there any plans to fix this for Silverlight Client? 

    Also can you provide an example code for WCF Extensibility. I started with creating my own custom EndpointBehavior using MessageInspector but then I think that will not work with Silverlight Client..at least I don't know how to add the Behavior pragmatically to a lightswitch instance.

    I then try to add a ServiceBehavior and use a MessageDispatchInspector but I can't add the behavior to the ServiceHost, or at least I am not sure how to add the behavior to the ServiceHost that the LightSwitch server project is using..

    Any guidance would be hugely appreciated. even if it is to confirm the WCF extensibility to fix this issue is not possible for Silverlight Client.

    thank you nutthinee

    
    Sunday, February 8, 2015 8:24 AM