Moved Thread: Silverlight 4 Service Reference doesn't acknowledge DataServiceProtocolVersion.V3
-
venerdì 9 marzo 2012 23:27
Zack Picki originally posted this question in the pre-release forums, which we're closing down. I'm re-posting it here so it'll catch some eyeballs:
"Hi,
I can't get Silverlight 4 to reference the correct assembly for June CTP.
In the web project I have references to:
C:\Program Files (x86)\Microsoft Data Services June 2011 CTP\bin\.NETFramework\Microsoft.Data.Services.dll
C:\Program Files (x86)\Microsoft Data Services June 2011 CTP\bin\.NETFramework\Microsoft.Data.Services.Client.dll
The WCF Data Service has "config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;" set correctly.
The markup may be the problem since it initialiy created with V2:
Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
is that correct for the June CTP V3?
I found that the markup needed to be changed for the March CTP to:
Factory="System.Data.Services.DataServiceHostFactory, Microsoft.Data.Services.Delta, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
but this does not work with the June CTP.
In SL4 I have reference to:
C:\Program Files (x86)\Microsoft Data Services June 2011 CTP\bin\Silverlight\Microsoft.Data.Services.Client.dll
When I add the service reference, it automatically keeps adding a reference to:
C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\System.Data.Services.Client.dll
which I then remove as it creates conflicts.
I need to set "_context.AddAndUpdateResponsePreference = DataServiceResponsePreference.IncludeContent;" which is only available in V3.
Checking the _context when it is initialized keeps telling me that the Protocol Version is V2
thus when I try to save my data I get a message saying:
"The request requires that version 3.0 of the protocol be used, but the MaxProtocolVersion of the data service context is set to V2. Set the MaxProtocolVersion to the higher version, and then retry the operation."
Does anyone have a solution for this?
Zack"
Tutte le risposte
-
lunedì 12 marzo 2012 18:08
Zack,
The exception you are seeing is being thrown on the client. The "DataServiceContext" class has a new constructor with V3 that takes in a MaxProtocolVersion. By default this parameter is set to V2. In order to fix the error, you need to construct your DataServiceContext passing in V3 to this constructor: http://msdn.microsoft.com/en-us/library/hh541123(VS.103).aspx.
You can do this in a number of ways, but probably the easiest way is to add a static factory method in your DataServiceContext's partial class that takes in the System.Uri:
partial class NorthwindEntities { private NorthwindEntities(Uri serviceRoot, DataServiceProtocolVersion maxVersion) : base(serviceRoot, maxVersion) { } public static NorthwindEntities Create(Uri serviceRoot) { return new NorthwindEntities(serviceRoot, DataServiceProtocolVersion.V3); } }
Use this factory method whenever you are creating your context class instead of the public constructor generated by the V2 Add Service Reference.
- Proposto come risposta Eric ErhardtMicrosoft Employee lunedì 12 marzo 2012 18:08

