繁体   English   中英

使用WCF数据服务的VerificationException

[英]VerificationException with WCF Data Services

我使用.Net 4.5.2和Entity Framework 6.1.3创建了一个带有实体框架的基本WCF数据服务。 在数据库中只有一个表。

这是配置:

public class MyDataService : DataService<DataItemsDataContext>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {            
            config.UseVerboseErrors = true;
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
            config.SetEntitySetAccessRule("DataItem", EntitySetRights.All);
        }
    }

当我启动项目时,我可以看到:

URL: http://localhost:49570/MyDataService.svc/

内容:

<service xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom" xml:base="http://localhost:49570/MyDataService.svc/">
<workspace>
<atom:title>Default</atom:title>
<collection href="DataItem">
<atom:title>DataItem</atom:title>
</collection>
</workspace>
</service>

当我选择表时,我得到以下异常:

URL: http://localhost:49570/MyDataService.svc/DataItem

内容:

<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code/>
<m:message xml:lang="en-US">An error occurred while processing this request.</m:message>
<m:innererror>
<m:message>Operation could destabilize the runtime.</m:message>
<m:type>System.Security.VerificationException</m:type>
<m:stacktrace>
 at: queryable_reader(Object )
 at: System.Data.Services.Providers.ReflectionServiceProvider.GetQueryRootForResourceSet(ResourceSet container)
 at: System.Data.Services.Providers.ReflectionDataServiceProvider.GetQueryRootForResourceSet(ResourceSet resourceSet)
 at: System.Data.Services.Providers.DataServiceProviderWrapper.GetQueryRootForResourceSet(ResourceSetWrapper resourceSet)
 at: System.Data.Services.RequestUriProcessor.ComposeExpressionForEntitySet(SegmentInfo segment, IDataService service, Boolean isLastSegment, Boolean checkRights)
 at: System.Data.Services.RequestUriProcessor.ComposeExpressionForSegments(IList`1 segments, IDataService service, Boolean isCrossReferencingUri)
 at: System.Data.Services.RequestUriProcessor.ProcessRequestUri(Uri absoluteRequestUri, IDataService service, Boolean internalQuery)
 at: System.Data.Services.DataService`1.ProcessIncomingRequestUri()
 at: System.Data.Services.DataService`1.HandleRequest()
</m:stacktrace>
</m:innererror>
</m:error>

它可能是一些.Net错误

什么可能导致这个? 我应该改变什么?

它似乎确实是一个错误(或至少是一个限制性功能)。

首先,我使用Entity Framework 6.1.3作为数据库ORM,并且存在错误。

当我切换回Entity Framework 5.0时 ,服务正常工作。

根据这篇知识库文章

假设您在计算机上将早期版本的.NET Framework升级到.NET Framework 4.5。 当您使用某些第三方控件时,您可能会收到System.Security.VerificationException异常。 如果满足以下条件,则会出现此问题:

  • 第三方控件使用泛型类型。
  • 通过声明标记为安全透明的程序集来启用CLR验证程序。

我认为,EF 6.x使用泛型类型,因此它会导致问题。

解决方法解决方案是使用Entity Framework 5.0。 而不是实体框架6.x.

http://blogs.msdn.com/b/odatateam/archive/2013/10/02/using-wcf-data-services-5-6-0-with-entity-framework-6.aspx有一个Nuget包应该有所帮助,但它仍处于预发布状态(2015/09/22)。

从2013年10月开始:“现在有一些令人兴奋的消息:您最终可以使用带有Entity Framework 6+的WCF数据服务!今天我们正在上传一个名为WCF数据服务实体框架提供商的新NuGet包。这个NuGet包填补了WCF之间的空白Data Services 5.6.0和Entity Framework 6+

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM