gpt4 book ai didi

c# - WCF 数据服务 5.6 快速入门

转载 作者:太空狗 更新时间:2023-10-29 20:01:18 24 4
gpt4 key购买 nike

几天来,我一直在尝试让 WCF 数据服务服务器正常工作。我今天终于退缩了,只是尝试完全按照快速启动显示的内容进行操作……没有别的……并且是在全新的项目中。那肯定行得通。

但它并没有……它以与我的其他测试相同的方式失败了。

我只是跟着这个example .使用 Visual Studio 2013 for Web express 和托管使用 IIS Express。我已经安装了 WCF 工具版本 5.6,因此 Visual Studio 具有 WFC 数据服务 5.6 模板。

它的要点是

创建一个 ASP.Net 应用程序选择 MVC 类型,不为 MVC 以外的任何内容添加任何文件夹,没有单元测试,个人帐户身份验证。

为 NorthWind 数据库添加一个 ADO.Net 实体数据模型,在 web.config 中调用 NorthwindEntities,导入所有表。

添加 WCF 数据服务 5.6 项,将其命名为 NorthWind.svc。

将 NorthWind.svc.cs 支持代码更改为以下内容。

using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
namespace StackOverflowApp
{
public class NorthWindService : DataService<NorthwindEntities>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
config.UseVerboseErrors = true;
config.SetEntitySetAccessRule("Orders", EntitySetRights.AllRead | EntitySetRights.WriteMerge | EntitySetRights.WriteReplace );
config.SetEntitySetAccessRule("Order_Details", EntitySetRights.AllRead| EntitySetRights.AllWrite);
config.SetEntitySetAccessRule("Customers", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
}
}

现在它已准备好构建和运行..它应该可以工作..是吗?

我运行它,然后导航到该服务。我收到以下投诉。

<div id="content">
<p class="heading1">Request Error</p>
<p>The server encountered an error processing the request. See server logs for more details.</p>
</div>

我该如何调试它?这不是导航到在应用程序中生成错误的页面或导航到不存在的页面时的典型响应。我感觉 data.service 系统正在生成此响应......它实际上开始处理请求......但由于某些迟钝的原因失败了。

我按照我认为的指示进行了发球,但显然我错过了一些东西。我已经多次逐步完成这个过程,试图找到我可能跳过但无济于事的内容。


更新:

啊哈.. 在另一个类似的问题下,他们建议使用 config.UserVerboseErrors = true 添加详细消息。这对我没有任何影响.. 但使用属性的替代方法确实如此!使用 [ServiceBehavior(IncludeExceptionDetailInFaults = true)] 装饰类,现在会产生这个更具描述性的错误。

The server encountered an error processing the request. The exception message is 'Expression of type 'System.Data.Entity.Core.Objects.ObjectContext' cannot be used for return type 'System.Data.Objects.ObjectContext''. See server logs for more details. The exception stack trace is: blahblah

最佳答案

听起来您使用的 Entity Framework 6 已经发布很久了。您需要执行一些额外的步骤才能让 WCF 数据服务 5.6 和 EF 6 很好地协同工作。

您需要添加额外的 WCF 数据服务 Entity Framework 提供程序 Nuget 包,而不是从 DataService<T> 继承您的服务, 你继承自 EntityFrameworkDataService<T> .

完整步骤在此处的数据服务博客上:http://blogs.msdn.com/b/astoriateam/archive/2013/10/02/using-wcf-data-services-5-6-0-with-entity-framework-6.aspx

关于c# - WCF 数据服务 5.6 快速入门,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20255201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com