2015-10-18 67 views
4

執行存儲過程所以我有一個WCF數據服務並與.NET 4.5運行時,EF6 & WCF數據服務5.6,並在InitializeService以下WCF數據服務使用OData的錯誤協議版本

public static void InitializeService(DataServiceConfiguration config) 
    { 
     config.SetEntitySetAccessRule("*", EntitySetRights.AllRead); 
     config.SetServiceOperationAccessRule("*", ServiceOperationRights.All); 
     config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3; 
     config.UseVerboseErrors = true; 
    } 

我有一個我已經添加了一個服務引用過,一切的.Net MVC應用程序似乎不過是工作和訪問,當我嘗試和返回複雜類型我得到以下錯誤的集合:

Collection types are only supported in version 3.0 of the OData protocol and higher versions. They are not supported in version 1.0. 

我也注意到我的service.edmx有dataService v1:

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

我已經測試了下面的存儲過程和參數提琴手服務URL,我可以看到它使用serviceVersion 1.0在頭然而,當我嘗試使用VAR它拋出上述異常的參數。

string querystring = string.Format("GetSecurityIdByName?securityName='{0}'", maincompany.Name); 
       IEnumerable<get_security_id_by_name_Result> getsecurityid = context.Execute<get_security_id_by_name_Result>(new Uri(querystring, UriKind.Relative), "GET", false); 

我在想什麼?我如何強制它/使用v3執行sproc?

TIA

回答

1

好,通過發送SendingRequest2()的正確版本解決了該問題,但感覺哈克,而不是「適當」的解決方案。也許這仍然是一個已知的bug,根據這篇文章,我是2012年的一名微軟員工!

https://social.msdn.microsoft.com/Forums/en-US/3a735526-59a9-494d-9240-7107e1ccceae/return-iqueryable-of-dtos-from-serviceoperation?forum=adodotnetdataservices

context.SendingRequest2 += (sender, eventArgs) => { 
    eventArgs.RequestMessage.SetHeader("MinDataServiceVersion", "3.0;NetFx"); 
}; 
相關問題