ServiceStack 在 .Net 框架 web 项目中使用 DotNetStandard 服务模型 [英] ServiceStack using DotNetStandard Service Model in .Net framework web project

查看:28
本文介绍了ServiceStack 在 .Net 框架 web 项目中使用 DotNetStandard 服务模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近使用 ServiceStack 创建了一个新的 DotNetCore Web 服务.ServiceModel 项目是一个 DotNet Standard 类库 v2.0.

在从我们用 DotNet Framework 4.6.1 编写的现有 Web 服务中引用新的 ServiceModel 时,我遇到了编译错误.看起来通过引用新的 ServiceModel,它正在拉入 ServiceStack.Interfaces.Core,它与 DotNet Framework 项目中已经引用的 ServiceStack.Interfaces 冲突.

我们目前不打算将这些现有服务升级到 DotNetCore.有没有办法在 DotNet Framework Web 服务中使用 DotNet Standard ServiceModel?

发现了一个类似的问题 这里.我的 ServiceModel 只引用了 ServiceStack.Interfaces.Core(5.1.0)..net Framework 项目面向 v4.6.1 并使用 ServiceStack v4.5.8.我是否需要升级到最新的服务堆栈才能使其工作?

在.net Framework项目中将ServiceStack版本升级到5.1.0.这修复了那些没有实现 IServiceClient 错误的服务.但是,现在我得到

  • 类型 'IReturn<>' 是在一个未定义的程序集中定义的参考.您必须添加对程序集的引用'ServiceStack.Interfaces,版本=5.0.0.0,文化=中性,PublicKeyToken=null'.

  • 方法的类型参数'IServiceGateway.Send(object)' 不能从用法.尝试明确指定类型参数.

解决方案

如果您想同时支持经典 ASP.NET Framework 项目和 .NET Core 项目,则需要多目标.有关详细信息,请参阅之前的答案:

https://stackoverflow.com/a/49417944/85785

如果您只想支持一个 ASP.NET Core .NET Framework 项目和一个 .NET Core 项目(即两个 ASP.NET Core 项目),您可以 参考 ServiceStack 的 *.Core 项目,其中仅包含 .NET Standard 版本.

或者,您可以避免共享 ServiceModel.dll 项目的二进制耦合,并让经典的 ASP.NET 项目通过 C# 添加 ServiceStack 参考.

We recently created a new DotNetCore web service using ServiceStack. The ServiceModel project is a DotNet Standard class library v2.0.

I am getting compiling errors while referencing the new ServiceModel from our existing web services that were written in DotNet Framework 4.6.1. Looks like by referencing the new ServiceModel, it is pulling in ServiceStack.Interfaces.Core which conflict with ServiceStack.Interfaces already referenced in the DotNet Framework project.

We are not looking to upgrade those existing services to DotNetCore yet. Is there a way to consume a DotNet Standard ServiceModel in a DotNet Framework web service?

[Edit 1]

Found a similar issue here. My ServiceModel only references ServiceStack.Interfaces.Core(5.1.0). The .net Framework project is targeting v4.6.1 and using ServiceStack v4.5.8. Do I need to upgrade to the latest Service Stack to make it work?

[Edit 2]

Upgraded the ServiceStack version to 5.1.0 in the .net Framework project. That fixed those Service not implementing IServiceClient errors. However, now I am getting

  • The type 'IReturn<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'ServiceStack.Interfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null'.

  • The type arguments for method 'IServiceGateway.Send(object)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

解决方案

If you want to support both classic ASP.NET Framework project and a .NET Core project you need to multi target. See this previous answer for details:

https://stackoverflow.com/a/49417944/85785

If you just want to support an ASP.NET Core .NET Framework project and a .NET Core project (I.e. both ASP.NET Core projects) you can reference ServiceStack’s *.Core projects which only contains .NET Standard builds.

Alternatively you can avoid the binary coupling of sharing your ServiceModel.dll project and have the classic ASP.NET projects reference your DTOs via C# Add ServiceStack Reference.

这篇关于ServiceStack 在 .Net 框架 web 项目中使用 DotNetStandard 服务模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆