WCF数据服务使用OData的错误协议版本
问题描述:
执行存储过程所以我有一个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
答
好,通过发送SendingRequest2()的正确版本解决了该问题,但感觉哈克,而不是“适当”的解决方案。也许这仍然是一个已知的bug,根据这篇文章,我是2012年的一名微软员工!
context.SendingRequest2 += (sender, eventArgs) => {
eventArgs.RequestMessage.SetHeader("MinDataServiceVersion", "3.0;NetFx");
};