locked
[BUG] Possible Known Issue where client is not encoding data put into the URL. RRS feed

  • Question

  • Client name is empty and client id is equals '#123'
    
    Client name and client id are string values

    var allclients = from client in this.ParentContext.Context.AllClients
                     where ((client.ClientName.Contains(clientName) || string.IsNullOrEmpty(clientName))
                     && (client.PK_ClientID.Contains(clientId) || string.IsNullOrEmpty(clientId)))
                     select client;
    

    Is being translated to the following HTTP Get

    GET /Services/PricingDataService.svc/AllClients()?$filter=(substringof('',ClientName)%20or%20true)%20and%20(substringof(' HTTP/1.1
    User-Agent: Microsoft ADO.NET Data Services
    Accept: application/atom+xml,application/xml
    Accept-Charset: UTF-8
    DataServiceVersion: 1.0;NetFx
    MaxDataServiceVersion: 1.0;NetFx
    Host: 127.0.0.1

    It seems that it doesnt like '#'

    UPDATE: Bug not in Data Services but elsewhere in the System.Net namespace. So topic subject has been changed to reflect that.

    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights. If this post is answered your question please mark as the answer and if it is helpful do like wise.
    • Edited by Daniel Portella Wednesday, May 13, 2009 8:39 AM Changed suvject to reflect the possible problem
    Tuesday, May 12, 2009 3:37 PM

Answers

All replies

  • Hi,

    I've reproduced the behavior you're seeing with the following code:

        class Client
        {
            public string ClientName
            {
                get;
                set;
            }
    
            public string PK_ClientID
            {
                get;
                set;
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                string clientName = "";
                string clientId = "#123";
    
                DataServiceContext ctx = new DataServiceContext(new Uri("http://localhost:8888/myService.svc"));
                var allClients = from client in ctx.CreateQuery<Client>("Clients")
                                 where ((client.ClientName.Contains(clientName) || string.IsNullOrEmpty(clientName))
                                 && (client.PK_ClientID.Contains(clientId) || string.IsNullOrEmpty(clientId)))
                                 select client;
                Console.WriteLine(allClients.ToString());
                List<Client> allClientsMaterialized = allClients.ToList();
            }
        }

    However, if you look at the console output of allClients.ToString(), you will see:

    http://localhost:8888/myService.svc/Clients()?$filter=(substringof('',ClientName) or true) and (substringof('#123',PK_ClientID) or false)

    So, the bug is not in the ADO.NET Data Services client, but rather somewhere in the System.Net stack.

    If we add the following code:

                ctx.SendingRequest += delegate(object sender, SendingRequestEventArgs eventArgs)
                {
                    Console.WriteLine(eventArgs.Request.RequestUri.ToString());
                    Console.WriteLine(eventArgs.Request.RequestUri.AbsoluteUri);
                    Console.WriteLine(eventArgs.Request.RequestUri.OriginalString);
                };
    We will see that the HttpWebRequest being built by the client still has the correct value for the request Uri (it prints the same uri seen above three times).

    I will check with some of the other team members, and try to find out where the bug really lies, and whether or not there is a known workaround.


    Matt Meehan, ADO.NET Data Services (Astoria)
    Tuesday, May 12, 2009 4:00 PM
    Moderator
  • Ok thank you would be appreciated, I am happy to know that Data Service is able to parse the expressions correctly. I am able to debug the code from astoria? The question is: Is the Data Service Code available on the microsoft symbol servers? can i download them and debug it myself?
    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights. If this post is answered your question please mark as the answer and if it is helpful do like wise.
    Tuesday, May 12, 2009 4:09 PM
  • I could be wrong, but I don't believe the symbols are available. I don't think the issue is occurring in the ADO.NET Data Services code, as demonstrated by the correctly-build HttpWebRequest seen above.

    I think the problem stems from the typical usage of '#' in a URL being for denoting an anchor reference, making it semantically meaningless for the actual request (ie, it just tells the browser where to scroll to once the page has loaded).

    Again, let me follow up with the team.

    Is it possible for you to simply strip special characters from your search strings? You could also try url-encoding them before using them in the query. I know neither is an imperfect solution, but they may get you around this issue for now.
    Matt Meehan, ADO.NET Data Services (Astoria)
    Tuesday, May 12, 2009 4:27 PM
    Moderator
  • It just occurred to me that the client might have a bug in that its not performing encoding on the special characters automatically. I'm not sure if this is intentional though, or if it would even fix the problem. I know there are some scenarios where there are issues with encoding as well.
    Matt Meehan, ADO.NET Data Services (Astoria)
    Tuesday, May 12, 2009 4:37 PM
    Moderator
  • So this is a known issue in the 3.5 sp1 release where the client is not encoding data that gets put into the URI.

    It has been fixed for the next release of ADO.NET Data Services, and should work correctly in the recently-released public CTP.

    Can you try out the CTP and see if it fixes the problem for you?

    You can find more information about the CTP here:

    ADO.NET Data Services Team Blog: ADO.NET Data Services v1.5 CTP1 -- Now Available for Download


    Matt Meehan, ADO.NET Data Services (Astoria)
    Tuesday, May 12, 2009 4:58 PM
    Moderator
  • I could be wrong, but I don't believe the symbols are available. I don't think the issue is occurring in the ADO.NET Data Services code, as demonstrated by the correctly-build HttpWebRequest seen above.

    I think the problem stems from the typical usage of '#' in a URL being for denoting an anchor reference, making it semantically meaningless for the actual request (ie, it just tells the browser where to scroll to once the page has loaded).

    Again, let me follow up with the team.

    Is it possible for you to simply strip special characters from your search strings? You could also try url-encoding them before using them in the query. I know neither is an imperfect solution, but they may get you around this issue for now.
    Matt Meehan, ADO.NET Data Services (Astoria)
    I understand that the error might not be in Data Service (Most likely not in there) but i would have liked to debug end to end. to see where it is.
    It is possible to remove the special characters, it i s just something i didnt expect to occurrer, I will tell my client that this is not supported and add a check on the object.

    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights. If this post is answered your question please mark as the answer and if it is helpful do like wise.
    Wednesday, May 13, 2009 8:34 AM
  • So this is a known issue in the 3.5 sp1 release where the client is not encoding data that gets put into the URI.

    It has been fixed for the next release of ADO.NET Data Services, and should work correctly in the recently-released public CTP.

    Can you try out the CTP and see if it fixes the problem for you?

    You can find more information about the CTP here:

    ADO.NET Data Services Team Blog: ADO.NET Data Services v1.5 CTP1 -- Now Available for Download


    Matt Meehan, ADO.NET Data Services (Astoria)
    Ah ah ok cool, I will download the code now and test it if it is fixed i will mark your reply as the answer.
    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights. If this post is answered your question please mark as the answer and if it is helpful do like wise.
    Wednesday, May 13, 2009 8:37 AM
  • I would recommend at least trying to manually url-encode the values, as it may work without having to forbid those characters.

    You can use HttpServerUtility.UrlEncode from System.Web to do this before using the string in the query.

    MSDN reference here: http://msdn.microsoft.com/en-us/library/zttxte6w.aspx

    Again, the best solution would probably be to upgrade to v1.5 when it is released, or use the CTP if not in a production environment.

    Matt Meehan, ADO.NET Data Services (Astoria)
    Wednesday, May 13, 2009 11:48 PM
    Moderator
  • I will try this and let you know asap. However currently I can not move to CTP as the application is on UAT.
    Daniel Portella - http://undocnet.blogspot.com - This posting is provided "AS IS" with no warranties, and confers no rights. If this post is answered your question please mark as the answer and if it is helpful do like wise.
    Friday, May 15, 2009 10:31 AM