Filling DataServiceCollection with sends DataServiceVersion of 1.0 RRS feed

  • Question

  • I am in the process of updating a project from WCF Data Services June 2011 CTP to version 5.0.2 (in Visual Studio 2012 but I have also tried going back to 2010 - using the v5 install to update the add service reference function).

    Most operations in the application complete successfully.

    The problem is, after doing the conversion, any calls to the service that use an OData v3 keyword (such as Any or All) return an exception stating:

    The DataServiceVersion '1.0' is too low for the request. The lowest supported version is '3.0'.

    The service is set to have max version 3 and I have followed the instructions for installing the update in the client.  After recreating the service reference the generated client class is setting the maxProtocolVersion of the DataServiceContext base class to v3.  The add service reference is also correctly adding the DLLs from 5.0.2 (Microsoft.Data.Services.Client.dll etc.)  The XML in service.edmx has DataServiceVersion as 1.0 and MaxDataServiceVersion as 3.0.  This line is as follows and is the second line in the file:

    <edmx:DataServices m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

    If I look at the HTTP header in Fiddler I see the following (I've shortend the query and table name because it also includes a number of other filter parameters):

    GET$expand=Note&$filter=(Note/any(x:substringof('test',x/Body)))&$orderby=Date%20desc HTTP/1.1
    User-Agent: Microsoft ADO.NET Data Services
    Accept-Charset: UTF-8
    DataServiceVersion: 1.0;NetFx
    MaxDataServiceVersion: 3.0;NetFx
    Accept: application/atom+xml,application/xml

    If I alter the DataServiceVersion to 3.0 and resend the request (from inside Fiddler) the data is returned as expected.  Data is also returned when executing this request directly from the browser which doesn't set any values at all.

    In the cases where this is failing I am building the query by building a DataServiceQuery using code such as the following:

    DataServiceQuery<Table> query = m_dataService.Table.Expand("Notes");

    I then calculate the filters (from the user interface) and apply them as a string parameter using query.AddQueryOption("$filter", queryString); etc.

    Then I pass this into a DataServiceCollection constructor.  This is the point where the exception is thrown.  In the release notes for this version it states there is a fix for a bug where the wrong dataserviceversion is sent when following a next link.  In my code this will call a next link if the exception was not thrown as the service is limiting the returned objects to 200 at a time.  However, I do not believe this is directly related as the exception is thrown when constructing the dataservicecollection (i.e. when making the first call).

    My question is: have I not completed the conversion process correctly or completely or can I force the dataserviceversion of the request to v3?  I know I can re-write the http request but I want to know if there is a better way of dealing with this.

    Tuesday, October 9, 2012 12:57 PM


  • Hi,

    I think the problem is that you're adding the filter as a string using AddQueryOption. The client library doesn't analyze the string to see if it contains V3 features. So it only determines the version of the request from the Table.Expand which is a V1 construct.

    You could either build the filter using LINQ expression trees in which case the library will analyze it correctly. Or don't use any of the query building methods, construct the entire URL yourself and use .Execute (which I think will always use the highest possible version, since it doesn't know).


    Vitek Karas [MSFT]

    • Marked as answer by Epic Wanderer Wednesday, October 10, 2012 8:44 AM
    Tuesday, October 9, 2012 2:32 PM