能否在c#中把WCF和Web API放在同一个解决方案中,共享同一个服务层?

问题描述 投票:0回答:1

For one of project requirement we need web API and wcf services the business logic is common for both, so want to keep WEB API and WCF in same solution. Is this possible anyone have such type of thing Please help me in this. Is this possible anyone have such type of thing Please help me in this.

c# wcf asp.net-web-api
1个回答
0
投票

这是可能的,也是像洋葱architecureN层architecureclean架构提供的功能之一。

简单的添加一个WebApi csproj和一个Wcf csproj到你的解决方案。然后在你的解决方案中添加一个businesslayer csproj。然后简单地在WebApi & Wcf项目中添加对businesslayer项目的引用。

然后确保在业务层类中保留所有的业务逻辑,你就可以了。

从架构的角度来看,你将拥有以下结构。

  • 解决方案层(WebApi & Wcf项目)[两个项目都依赖于业务逻辑层]。
  • 业务逻辑层(业务层csproj)[不依赖任何东西]

如果你也从底层数据库、其他API或文件中读取数据,我还建议添加一个底层,叫做数据访问层(另一个csproj),在这里你可以完成所有的数据访问,比如查询数据库。

然后你会有类似这样的东西(箭头是依赖关系)。

enter image description here

需要注意的是:如果你想将WCF与.Net Core WebApi结合起来使用,请确保BusinessLayer.csproj是一个.net标准项目,这样你就可以同时运行这两个项目。这是因为WCF运行在.Net框架上。

© www.soinside.com 2019 - 2024. All rights reserved.