【发布时间】:2021-12-20 10:50:50
【问题描述】:
我正在运行一个非常简单的程序,我有一个 ASP.NET 项目,我在其中添加了 WcfDataService1 文件,文件名是 WcfDataService1.svc,如下所示:
namespace WebApplication
{
public class WcfDataService : EntityFrameworkDataService<SampleDatabaseEntities>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
// config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
// config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
}
我还检查了我的视图标记:
<%@ ServiceHost Language="C#" Debug="true" Factory="System.ServiceModel.Activation.WebServiceHostFactory, System.ServiceModel.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Service="WebApplication.WcfDataService" CodeBehind="WcfDataService.svc.cs" %>
但它仍然向我显示以下错误:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The type 'WebApplication.WcfDataService', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
更新:
我重新启动电脑,然后它显示以下问题:
Could not load file or assembly 'Microsoft.Data.Services, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
我尝试了很多方法,但仍然显示错误。
I checked in my C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics there are 5.6.2 version dlls are there, I replaced them with 5.6.4 but still getting the same error.
【问题讨论】:
-
什么时候出现这个错误?在运行服务时还是在调用服务时?
-
运行服务时
-
当我在运行按钮 IIS 上播放时,它会在浏览器上显示错误
-
看起来您的服务被定义为“WcrDataService1”,但您的标记指的是“WcfDataService”。将您的标记更改为 Service="WebApplication.WcfDataService1" CodeBehind="WcfDataService1.svc.cs"
-
其实是WcfDataServce,没有解决问题
标签: c# asp.net wcf wcf-data-services wcf-binding