WCF包装了asp.net mvc的服务层

时间:2022-10-28 16:39:39

I'd like to expose certain methods of my service layer as a WCF service. If I make my whole service layer as wcf methods, would the calls from my web app be slowed down because I'm converting to and from xml for no reason? As shown in this image:

我希望将我的服务层的某些方法公开为WCF服务。如果我将整个服务层作为wcf方法,那么来自web应用程序的调用会不会因为我毫无理由地在xml之间进行转换而减慢?如图所示:

WCF包装了asp.net mvc的服务层

How would my project be layered or structured?

我的项目是分层的还是结构化的?

2 个解决方案

#1


1  

WCF services are just a contract.

WCF服务只是一个合同。

You can easily expose service classes as a contract for a WCF service and also just new them up like normal classes for use in your MVC application. You won't be creating XML or SOAP/Http messages if you simply use your service classes as just classes.

您可以轻松地将服务类公开为WCF服务的契约,也可以像普通类一样将它们更新到MVC应用程序中。如果只是将服务类作为类来使用,就不会创建XML或SOAP/Http消息。

#2


1  

If I make my whole service layer as wcf methods, would the calls from my web app be slowed down because I'm converting to and from xml for no reason?

如果我将整个服务层作为wcf方法,那么来自web应用程序的调用会不会因为我毫无理由地在xml之间进行转换而减慢?

Compared to calling the service methods directly, the WCF methods will be slower because of the network latency and serialization.

与直接调用服务方法相比,由于网络延迟和序列化,WCF方法的调用速度会更慢。

Depending on your requirements there are different techniques. In all cases you should encapsulate your service layer into a separate reusable library. Then start by using this library in your MVC application. If you are happy with the results we are finished. Now if you later need interoperability and exposure of your service layer to third parties you could easily expose this library to a WCF service.

根据您的需求,有不同的技术。在所有情况下,都应该将服务层封装到一个单独的可重用库中。然后在MVC应用程序中使用这个库。如果你对结果满意,我们就结束了。现在,如果您以后需要将服务层的互操作性和公开给第三方,您可以很容易地将这个库公开给WCF服务。

#1


1  

WCF services are just a contract.

WCF服务只是一个合同。

You can easily expose service classes as a contract for a WCF service and also just new them up like normal classes for use in your MVC application. You won't be creating XML or SOAP/Http messages if you simply use your service classes as just classes.

您可以轻松地将服务类公开为WCF服务的契约,也可以像普通类一样将它们更新到MVC应用程序中。如果只是将服务类作为类来使用,就不会创建XML或SOAP/Http消息。

#2


1  

If I make my whole service layer as wcf methods, would the calls from my web app be slowed down because I'm converting to and from xml for no reason?

如果我将整个服务层作为wcf方法,那么来自web应用程序的调用会不会因为我毫无理由地在xml之间进行转换而减慢?

Compared to calling the service methods directly, the WCF methods will be slower because of the network latency and serialization.

与直接调用服务方法相比,由于网络延迟和序列化,WCF方法的调用速度会更慢。

Depending on your requirements there are different techniques. In all cases you should encapsulate your service layer into a separate reusable library. Then start by using this library in your MVC application. If you are happy with the results we are finished. Now if you later need interoperability and exposure of your service layer to third parties you could easily expose this library to a WCF service.

根据您的需求,有不同的技术。在所有情况下,都应该将服务层封装到一个单独的可重用库中。然后在MVC应用程序中使用这个库。如果你对结果满意,我们就结束了。现在,如果您以后需要将服务层的互操作性和公开给第三方,您可以很容易地将这个库公开给WCF服务。