什么时候不应该使用 Web 服务? [英] When should a web service not be used?

查看:28
本文介绍了什么时候不应该使用 Web 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用网络服务通常是一种极好的架构方法.而且,随着 .Net 中 WCF 的出现,它变得更好了.

Using a web service is often an excellent architectural approach. And, with the advent of WCF in .Net, it's getting even better.

但是,根据我的经验,有些人似乎认为应该始终在数据访问层中使用 Web 服务来调用数据库.我不认为网络服务是通用的解决方案.

But, in my experience, some people seem to think that web services should always be used in the data access layer for calls to the database. I don't think that web services are the universal solution.

我正在考虑拥有几十个用户的较小的 Intranet 应用程序.Web 应用程序及其 Web 服务部署到一台 Web 服务器,而不是 Web 场.将来不会有另一个 Web 应用程序可以使用此特定 Web 服务.在我看来,调用 Web 服务的成本不必要地增加了 Web 服务器的负担.进程间调用会影响性能.维护和调试 Web 应用程序和 Web 服务的代码更为复杂.部署也是如此.我只是没有看到在这里使用网络服务的优势.

I am thinking of smaller intranet applications with a few dozen users. The web app and its web service are deployed to one web server, not a web farm. There isn't going to be another web app in the future that can use this particular web service. It seems to me that the cost of calling the web service unnecessarily increases the burden on the web server. There is a performance hit to inter-process calls. Maintaining and debugging the code for the web app and the web service is more complicated. So is deployment. I just don't see the advantages of using a web service here.

可以通过创建两个版本的网络应用程序来测试这一点,有和没有网络服务,并进行压力测试,但我没有这样做.

One could test this by creating two versions of the web app, with and without the web service, and do stress testing, but I haven't done it.

您对为小型网络应用程序使用网络服务有意见吗?在其他任何情况下 Web 服务都不是一个好的架构选择?

Do you have an opinion on using web services for small-scale web app's? Any other occasions when web services are not a good architectural choice?

推荐答案

Web 服务对于数据访问来说绝对是一个糟糕的选择.这是大量开销和复杂性,但收益几乎为零.

Web Services are an absolutely horrible choice for data access. It's a ton of overhead and complexity for almost zero benefit.

如果您的应用要在一台机器上运行,为什么要拒​​绝它进行进程内数据访问调用的能力?我不是在谈论从您的 UI 代码直接访问数据库,而是在谈论将您的存储库抽象出来,但仍将它们的程序集包含在您正在运行的网站中.

If your app is going to run on one machine, why deny it the ability to do in-process data access calls? I'm not talking about directly accessing the database from your UI code, I'm talking about abstracting your repositories away but still including their assemblies in your running web site.

在某些情况下,我会推荐网络服务(我假设您指的是 SOAP),但这主要是为了互操作性.

There are cases where I'd recommend web services (and I'm assuming you mean SOAP) but that's mostly for interoperability.

这里的服务粒度也有问题.SOA 意义上的服务将封装操作或业务流程.数据访问方法只是该过程的一部分.

The granularity of the services is also in question here. A service in the SOA sense will encapsulate an operation or a business process. Data access methods are only part of that process.

换句话说:

  - someService.SaveOrder(order);  // <-- bad
    // some other code for shipping, charging, emailing, etc

  - someService.FulfillOrder(order);  //<-- better
    //the service encapsulates the entire process

为了Web服务而使用Web服务是不负责任的编程.

Web services for the sake of web services is irresponsible programming.

这篇关于什么时候不应该使用 Web 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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