locked
Lightswitch 2.0 OData Protocol limits strings to 8072 in length RRS feed

  • Question

  • Hi -

    I have a Lightswitch application that we just converted to LS 2.0  An area of our application consumes a large XML string for deserializing and processing.  However, in LS 2.0 I get the error "Invalid URL:  The Uri string is too long", I am using Entity Framework as the data access point for our application.

    In my reading I understand that given the new access method of OData the string size is limited to 8072. 

    Any advice on how to render back the XML from Entity Framework to a LightSwitch Data Source?

    Thanks in advance, this forum continues to help me and provide lots of great info.


    Emma

    Wednesday, January 16, 2013 7:25 PM

All replies

  • Hi,

    Could you post your code that causes the error? It seems is not a LightSwitch issue. Probably you call some method in a wrong way, such as passing raw data of the xml string where the URL is needed:

    Invalid URI: The Uri string is too long


    Allen Chen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.



    Tuesday, January 22, 2013 7:33 AM
    Moderator
  • Hi -

    We are calling an object that returns the XML to be deserialzied by the client.  Here is the line of code that it fails on.

    DetailSet detailset = this.DataWorkspace.XpressDomainServiceData.DetailSet.Where(x => x.DetailSetId == 1).FirstOrDefault();

    The detail set has 3 properties each representing a different XML string to be processed by the LightSwitch application.

    This works fine if I change the DetailSetId to render a smaller XML string, the string gets returned and the data loads correctly into the Lightswitch application.  When I enable trace I see a status code of 500 with the trace information included at the bottom of the message.  I also watch the traffic in SQL Profiler and see that the request is a simple SQL statement.

    I am thinking that because Entity Framework doesn't support the XML data type from the database it translates it to a string and returns that to the Lightswitch data source which then throws the error.  In my reading I understand that this wasn't a problem with Lightswitch 1.0 because the convesation between the client and server was using RIA Services and now that it is using OData Protocol there are some restrictions.  Just guessing :-)

    Any thoughts or feedback is appreciated.

    Microsoft.LightSwitch.Security [Microsoft.LightSwitch.Security][Application:Information][SecurityState:User] sampleuser(Sample User)  

    Microsoft.LightSwitch.Security [Microsoft.LightSwitch.Security][Application:Information][SecurityState:EffectivePermissions] Effective Permissions: LightSwitchApplication:AccountUser 8.21333437629643E-05 0.000082

    Microsoft.LightSwitch.DataService [Microsoft.LightSwitch.DataService][Application:Information][LightSwitchServiceApplication.XpressDomainServiceData:DetailSet] Executing 'DetailSet' 0.00101772711336217 0.000936

    Microsoft.LightSwitch.DataService [Microsoft.LightSwitch.DataService][Application:Information][LightSwitchServiceApplication.XpressDomainServiceData:DetailSet:DataProviderQuery] source.Where(element => (element.DetailSetId == 1)) 0.00499337206265042 0.003976

    Microsoft.LightSwitch.DataService [Microsoft.LightSwitch.DataService][Application:Information][LightSwitchServiceApplication.XpressDomainServiceData:DetailSet:QueryExecuted] The query returned 1 results. 0.0715009868572682 0.066508


    Emma

    Wednesday, January 23, 2013 3:53 PM
  • Hi,

    Please refer to below thread:

    After upgrade to VS 2012 - Invalid URI: The URI string is too long

    Does it help?


    Allen Chen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, January 24, 2013 3:01 AM
    Moderator
  • Hi -

    Yes I read the article that you referenced when I first had this problem. 

    The link/article is related to the use of the nvarchar(MAX) column, I am using Entity Framework and the data is already stored in XML Data Type in the DB.  I guess because Entity Framework (v4 or v5) DOESN'T support XML Data types and translates it into a nvarchar(MAX) string type I am in a similiar situation in that the MAX is being reached and not returned to the LightSwitch Client. 

    Given that Entity Framework is a part of system archietecture I guess the problem is rooted there?  Any experience or advice?


    Emma

    Thursday, January 24, 2013 10:33 AM
  • One other thing, I forgot to mention that Entity Framework does offer a work-around, a little costly but a work-around.  The Entity Framework posts say to do this ...

    Create a new property on data object that shadows the string property and returns a XElement type to the calling application. 

    When I gave this a try LightSwitch Data Sources reported "The data type XElement is not supported; the property was excluded."  I get the same message if I try to return a XmlReader. 

    What datatype should I use to have Lightswitch recognize a property of XML type??


    Emma

    Thursday, January 24, 2013 11:15 AM
  • LightSwitch only supports primitive data types.

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

    Thursday, January 24, 2013 12:22 PM
    Moderator
  • Thanks for the response Yann.  So understanding that Lightswitch only supports primitive data types then my data source uses a string.  OK , no problem there.  So then why am I getting the error about the URL being too long?

    Just to recap here is what is going on:

    1. SQLServer 2008 R2 has a table called DetailSet with 3 columns all XML Data Type
    2. Entity Framework is built by reverse engineering the table and creating the object.  Creates an object with 3 properties all string types (bc EF doesn't support XML data type)
    3. Lightswitch data source consumes the RIA Service that Entity Framework exists in and creates a table with 3 properties all string types (LS only supports primitive data types)
    4. Everything works fine in LS 1.  LS 2 when loading an XML string length = 22789 WORKS, string length = 338714 FAILS we get Invalid URI:  The Uri string is too long.  Fails on this line of code DetailSet detailset =this.DataWorkspace.XpressDomainServiceData.DetailSet.Where(x => x.DetailSetId == 1).FirstOrDefault(); 

    Ideas?


    Emma

    Thursday, January 24, 2013 2:41 PM
  • Hi Emma,

    Unfortunately, this is an OData restriction, not a LightSwitch one. So the maximum length of the string is determined by the OData protocol, not LightSwitch.

    Until the protocol is updated to allow longer string values, I don't see any way around this.

    In LS1, RIA Services was the data persistence mechanism that was used internally by LightSwitch, which didn't have this restriction. In LS2, RIA Services was replaced with OData.

    Does that make sense? I know it won't be what you want to hear. :-(


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

    Friday, January 25, 2013 2:30 AM
    Moderator
  • Hi -

    Thanks for the response about OData however, I have done some more testing and found this.  Loading of large XML WORKS IF the application type uses a DataSource of Database, it FAILS when the DataSource uses a WCF RIA Service. 

    I thought the OData protocol commuication was between the LS Client and LS Server (a.k.a DataSource) so regardless of the provider of data (database or WCF RIA Service) the OData limits would come into play and both scenario's would fail?

    Thoughts?


    Emma

    Friday, January 25, 2013 11:46 AM