简体   繁体   English

在 .NET Core 项目中找不到 System.ServiceModel

[英]System.ServiceModel not found in .NET Core project

I have a .NET Core xUnit project.我有一个 .NET Core xUnit 项目。 I'm trying to call a WCF service from it but get the following exception:我正在尝试从中调用 WCF 服务,但出现以下异常:

System.InvalidOperationException occurred
  HResult=0x80131509
  Message=An error occurred while loading attribute 'ServiceContractAttribute' on type 'IMyContract'.  Please see InnerException for more details.

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

It works with a Framework 4.7 project with the same Nuget Package System.ServiceModel.Http.4.3.0 .它适用于具有相同 Nuget 包System.ServiceModel.Http.4.3.0的 Framework 4.7 项目。

Microsoft has made available the relevant assemblies as packages on NuGet now. Microsoft 现在已在 NuGet 上以包的形式提供相关程序集。

System.ServiceModel.Primitives is the base package; System.ServiceModel.Primitives是基础包; add the others if necessary to your project.如有必要,将其他人添加到您的项目中。

在此处输入图片说明

If you are using .NET Standard 2.0 (that's what I tested with), you can install compatible NuGet packages.如果您使用.NET Standard 2.0 (这是我测试过的),您可以安装兼容的NuGet包。

The basic service model is available in System.ServiceModel.Primitives (currently v4.4.0). System.ServiceModel.Primitives (当前为 v4.4.0)中提供了基本服务模型。

If required, install System.ServiceModel.Http as well.如果需要,还安装System.ServiceModel.Http

The Microsoft WCF Web Service Reference Provider wraps SvcUtil.exe and will generate a .NET Standard project from your endpoint. Microsoft WCF Web 服务引用提供程序包装 SvcUtil.exe 并将从您的终结点生成一个 .NET Standard 项目。 Look in the project file and you'll see the ServiceModel references that will work for you.查看项目文件,您将看到适用于您的 ServiceModel 引用。

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.3.0" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.3.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.3.0" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.3.0" />
    <PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
  </ItemGroup>
</Project>

When I needed to do this I was able to use the generated class library in my .NET Core project.当我需要这样做时,我能够在我的 .NET Core 项目中使用生成的类库。

I had same issue, i had to add .asmx web service into my class library asp.net core project, i tried to add reference directly by add connected service option but i wan unable to see any config file and lots of references errors also, below are the steps by which i solve my problem.我遇到了同样的问题,我不得不将 .asmx Web 服务添加到我的类库 asp.net 核心项目中,我尝试通过添加连接的服务选项直接添加引用,但我无法看到任何配置文件和大量引用错误,以下是我解决问题的步骤。

1-Create library project name Service Mapping 2-Create folder Web References and then create inside folder ClientHotel 3-Open terminal in visual studio from view ---> terminal --- command prompt. 1-创建库项目名称服务映射 2-创建文件夹 Web 引用,然后在文件夹 ClientHotel 内创建 3-从视图 ---> 终端 --- 命令提示符在 Visual Studio 中打开终端。 4-Integrate asmx service by command svcutil http://abctest.asmx (.asmx URL) inside inside ClientHotel folder. 4-通过 ClientHotel 文件夹内的命令 svcutil http://abctest.asmx (.asmx URL) 集成 asmx 服务。

5-it will create .cs class and output.config file with references in it. 5-它将创建 .cs 类和 output.config 文件,其中包含引用。 6-Now i had errors of references like the type or namespace servicecontractattribute does not exist in namespace System.ServiceModel etc. 6-现在我有引用错误,例如命名空间 System.ServiceModel 等中不存在类型或命名空间 servicecontractattribute。

7-Install Package System.ServiceModel.Primitives Then all references errors will be gone. 7-Install Package System.ServiceModel.Primitives 然后所有的引用错误都会消失。

That is how i was able to add .asmx service to my class library project.这就是我能够将 .asmx 服务添加到我的类库项目的方式。

暂无
暂无

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

相关问题 目标.net框架类库,具有来自.net核心应用程序的System.ServiceModel依赖项 - target .net framework class library with System.ServiceModel dependency from a .net core application System.ServiceModel引用 - System.ServiceModel References System.ServiceModel消失 - System.ServiceModel disappear System.ServiceModel缺失 - System.ServiceModel missing 找不到配置绑定扩展“system.serviceModel/bindings/basicHttpsBinding” - Configuration binding extension 'system.serviceModel/bindings/basicHttpsBinding' could not be found 找不到配置绑定扩展名&#39;system.serviceModel / bindings / pollingDuplexHttpBinding&#39; - Configuration binding extension 'system.serviceModel/bindings/pollingDuplexHttpBinding' could not be found 部署WCF客户端时出错 - 在SQL Catalog中找不到&#39;system.servicemodel&#39; - Error deploying WCF Client - 'system.servicemodel was not found in SQL Catalog' 找不到我的CLR项目的System.ServiceModel参考 - Can't Find System.ServiceModel Reference for my CLR Project .NET 核心与 .NET 框架 - 无法加载文件或程序集'System.ServiceModel,不应加载参考程序集以执行 - .NET Core vs .NET Framework - Could not load file or assembly 'System.ServiceModel, Reference assemblies should not be loaded for execution System.ServiceModel 错误 使用 ASP.NET 核心 ZDB974238714CA8DE6FZAACE714CA8DE6FZAACE714CA8DE6FZAACE7 中嵌入 Windows 服务中的 WCF 时不支持操作 - System.ServiceModel error Operation not supported when consuming WCF embedded in Windows Service in ASP.NET Core API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM