1

I'm migrating a system to its version 2.0. It's escalating so I want to build a WCF. This is the first time for me working with a WCF so this may be kind of basic, still, any heads up will be very much appreciated.

The existing system consists of a 3 layered proccess.

  1. UI based on WebForms.
  2. Business Layer.
  3. DAL.

For this 2.0 version what I'd like to achieve is to leave webforms behind, moving to a more mvc oriented interface. And, as I've already said, to use some sort of web service to get through in order to connect to my db source.

The question is as follows. I've been investigating and reading about wcf/restful and in the Iservice.cs I can see the interface and the DataContract with its DataMembers. The scratching-head part is that I already have my classes defined on the other layers. So, what is it meant to be done? Should I define my classes inside the WCF one by one aswell? Can't I just reference my DAL/Object Layer and use the resources available there? Should I add another proyect to the existing VS2010 solution or should I leave the wcf alone?

I'd love to get some input on best practices also, if you may.

4

2 回答 2

2

如果 REST 真的是您所追求的,那么除了 WCF 之外,还有其他选择。WCF 在大多数情况下通常是矫枉过正的,因此请考虑研究:

  1. ASP.NET Web API
  2. ServiceStack

这两个选项都适用于 ASP.NET MVC 和 ASP.NET WebForms,尽管大多数ASP.NET Web API示例将与 ASP.NET MVC 一起使用,这就是您想要在其中使用它的场景。

您可以将 ASP.NET Web API 或 ServiceStack 视为架构中的另一层,并像引用业务或数据访问层一样将其作为解决方案中的单独项目进行引用。

于 2013-11-05T12:38:24.577 回答
1

更好的方法是,为 WCF 服务添加另一个单独的层,给 DAL 引用它,同时也给 DAL 引用 BAL。并且不要给 WCF 项目引用任何一个,因为您希望它是 RESTFULL(即只能通过 HTTP、ftp 等协议访问)

这里的 Iservice.cs 只是向外部世界公开方法的接口,它描述了哪些数据,以什么形式以及将在哪里找到。只需将该接口实现到 WCF 项目中的任何存储库类,它将进一步为您从 DAL 获取数据。业务层是唯一会与服务层对话的层。

将 DAL 引用添加到 BAL 仅适用于实体的元数据。

如果我错了,请回复我。

于 2013-11-05T12:38:09.387 回答