【问题标题】:The type or namespace name 'Service Host' could not be found in .NET5在 .NET5 中找不到类型或命名空间名称“服务主机”
【发布时间】:2021-08-30 10:05:03
【问题描述】:

我最近将我的 .NET 框架 WCF 应用程序转换为 .NET5。

我收到Service Host 找不到错误。

“文件”不包含“GetAccessControl”的定义

我已经安装了这些 nuget 包,但没有运气。 System.ServiceModel.Primitives System.ServiceModel.Http System.ServiceModel.Security System.ServiceModel.Duplex System.ServiceModel.NetTcp System.Private.ServiceModel

我不确定 .NET5 中 Service HostAccess Control 的替换是什么。

有人可以帮帮我吗?

serviceHost = new ServiceHost(typeof(Api));
  FileSecurity fileSecurity = File.GetAccessControl(outputFile);

【问题讨论】:

  • 您可以查看此链接:ServiceHost Class
  • @Jiayao 提问者询问 .NET Core (NET 5.0) 类,而不是 .NET Framework 的 ServiceHost。这是不同的,因为 ServiceHost 不是默认 .NET Core SDK 和运行时库的一部分。

标签: wcf .net-5


【解决方案1】:

System.ServiceModel.*(通常也称为 WCF 客户端)的类库可作为单独的 nuget 包使用。

.NET 5.0 最兼容的版本是 System.ServiceModel.* 版本 4.8.1,因此您应该使用此版本。

对于 ServiceHost,.NET Core 不提供此功能。因为这意味着代码将充当 WCF 作为服务器,而不是 WCF 客户端。根据这篇博文,微软自己已经声明不支持 WCF 作为服务器:https://devblogs.microsoft.com/dotnet/supporting-the-community-with-wf-and-wcf-oss-projects/

幸运的是,OSS 一直在努力为 .NET Core 提供 WCF 服务器支持,它被称为 CoreWCF:

https://github.com/CoreWCF/CoreWCF

目前(据我所知)它支持 BasicHttpBinding 和 TCP 绑定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-12
    • 2011-05-13
    • 2013-03-25
    • 2012-06-19
    • 2017-11-29
    • 2012-09-27
    • 2011-05-06
    相关资源
    最近更新 更多