[英]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 项目。
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.