当前位置: 首页 > 知识库问答 >
问题:

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

卫彭亮
2023-03-14

我有一个. NET核心xUnit项目。我试图从它调用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.

它与具有相同Nuget Package System.ServiceModel.Http.4.3.0的Framework 4.7项目配合使用。

共有3个答案

壤驷志学
2023-03-14

Microsoft WCF Web Service Reference Provider 包装 SvcUtil.exe并将从终结点生成 .NET Standard 项目。查看项目文件,您将看到适合您的服务模型参考。

<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>

当我需要这样做时,我能够在.NETCore项目中使用生成的类库。

谢修真
2023-03-14

如果您使用的是.NET标准2.0(这是我测试的),则可以安装兼容的NuGet软件包。

基本服务模型可在System. ServiceModel. Primitics(当前为v4.4.0)中找到。

如果需要,也可以安装 System.ServiceModel.Http

金钊
2023-03-14

Microsoft 现已在 NuGet 上将相关程序集作为包提供。

System.ServiceModel.Primitives 是基本包;如有必要,将其他项目添加到项目中。

更新(2022年4月28日):

WCF已部分移植到. NET 5,其官方库名为CoreWCF:https://devblogs.microsoft.com/dotnet/corewcf-v1-released/

 类似资料:
  • 我目前正在使用Android Studio,我正在尝试进行重建,但我得到以下错误。 我会尝试“try:run with--stacktrace”,但是,我不确定如何做到这一点。有人能帮我排除这个问题吗?谢谢!

  • 我有3个项目,ProjectB,ProjectC。 当我构建ProjectB时,它没有任何问题。但是当我试图构建ProjectA时,它在控制台上出现以下错误而失败。 评估项目“:ProjectB”时出现问题。在项目:ProjectB中找不到路径为:ProjectC的项目。 build.gradle-ProjectC settings.gradle-ProjectC build.gradle - 项

  • 我在java代码中使用apollo graphql客户端。我的gradle文件是 我已经遵循了本文中提到的文档https://github.com/apollographql/apollo-android我在第四步和第五步被卡住了。无法添加 在gradle文件中,在执行命令gradlew generateApollo时,在根项目“testProject”中找不到任务“generateApolloS

  • 我的web.xml security-config.xml: 我找到了这个主题,但我不知道他现在是如何解决Spring的:异常启动过滤器springSecurityFilterChain 警告:org.springframework.web.context.support.xmlWebApplicationContext-从上下文关闭java.lang.IllegalStateException上

  • 我从2小时起就开始了,请帮忙:/

  • 我想部署一个库到我公司的远程存储库。 这是我第一次想将库项目部署到远程存储库。 我收到以下错误消息: org.sonatype.aether.transfer.artifactNotFoundException:找不到工件com.http: httpkit: jar: 0.0.1internal.repo(http://jenkins.internal.com/) 也许我理解了一些完全错误的地方,

  • 我正在尝试用从本地文件解析。但我的IDE找不到这个文件。 项目结构: 下面是我的代码: 我该怎么修好它? 附注:将目录名从更改为。