0

我完全不熟悉ADO.NET/WCF數據服務。在我第一次設置和測試ADO.NET數據服務,我就遇到了這個令人費解的錯誤:如何將ADO.NET數據服務MaxProtocolVersion設置爲使用V2?

The response requires that version 2 of the protocol be used, but the MaxProtocolVersion of the data service is set to DataServiceProtocolVersion.V1.

參考網上表明,我需要設置:

config.DataServiceBehavior.MaxProtocolVersion = Common.DataServiceProtocolVersion.V2 

但是這個屬性是不可用於智能感知,並在我手動編寫代碼時產生編譯錯誤。

我正在使用Visual Studio 2008 SP1,.NET 3.5 SP1和VB.NET。如何啓用協議的版本2?

回答

1

後大約一天的時間和搜索(並重新應用VS2008 SP1)的一半,該博客文章的最後茅塞頓開:

Astoria V.Next Ships for .NET 3.5 SP1 -> Versioning Issue

原來一切都很好,我的安裝,但我不得不跳過因爲InitilizeService()方法的簽名曾經如此微妙地改變過。斯蒂芬表示復地在他的博客:

1: //change the IDataServiceConfiguration to DataServiceConfiguration 
2: public static void InitializeService(DataServiceConfiguration config) 
3: { 
4:  config.SetEntitySetAccessRule("*", EntitySetRights.All); 
5:  //take advantage of the "2.0" features 
6:  config.DataServiceBehavior.MaxProtocolVersion = 
7:   System.Data.Services.Common.DataServiceProtocolVersion.V2; 
8: } 

The first thing that you need to change is on line 2, change the interface IDataServiceConfiguration to be just DataServiceConfiguration (I am sure that there is a better way to do this, I have not figured it out yet.). Next, set the MaxProtocolVersion property of DataServiceBehavior to V2. After that you can take advantage of all the new features!

重點煤礦。簡單的「我」造成的差異真是太棒了。要回答斯蒂芬的關注,這也是MSDN備份,但是他們目前不參考接口VS實施對象指出的區別:

Configuring the Data Service (ADO.NET Data Services)

下面是VB代碼:

'change the IDataServiceConfiguration to DataServiceConfiguration 
Public Shared Sub InitializeService(ByVal config As DataServiceConfiguration) 
    config.SetEntitySetAccessRule("*", EntitySetRights.All) 
    'take advantage of the "2.0" features 
    config.DataServiceBehavior.MaxProtocolVersion = System.Data.Services.Common.DataServiceProtocolVersion.V2 
End Sub 

編譯,測試並通過。我剛剛踏出了一個更大的世界......

相關問題