Web 服务与共享库 [英] Web Service vs. Shared Library

查看:24
本文介绍了Web 服务与共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的发现,这个问题在 SO 上被问过几次:

This question has been asked a few times on SO from what I found:

什么时候不应该使用网络服务?Web 服务还是 DLL?

答案有所帮助,但它们都指向特定场景.我想对此有一个更一般的想法.

The answers helped but they were both a little pointed to a particular scenario. I wanted to get a more general thought on this.

什么时候应该考虑 Web 服务而不是共享库 (DLL),反之亦然?

When should a Web Service be considered over a Shared Library (DLL) and vice versa?

推荐答案

我的想法:

Web 服务是为机器互操作而设计的,旨在覆盖受众使用 HTTP 作为传输方式很容易.

A Web Service was designed for machine interop and to reach an audience easily by using HTTP as the means of transport.

一个优点是,通过发布服务,您还可以使用服务于潜在的广大受众(通过网络或至少在整个整个公司)和/或很大程度上不受您的控制/影响/沟通渠道你不介意或者这是想要的.作为客户,服务的使用要容易得多只需拥有互联网连接并使用该服务即可.不像图书馆可能不是那么容易做到(但可以做到).该服务的使用在很大程度上是开放的.您将它提供给任何认为可以使用它的人以及他们认为如何使用它的人.

A strong point is that by publishing the service you are also opening the use of the service to an audience that is potentially vast (over the web or at least throughout the entire company) and/or largely outside of your control / influence / communication channel and you don't mind or this is desired. The usage of the service is much easier as clients simply have to have an internet connection and consume the service. Unlike a library which may not be so easily done (but can be done). The usage of the service is largely open. You are making it available to whomever feels they could use it and however they feel to use it.

但是,网络服务通常较慢,并且依赖于互联网连接.
通常比代码库更难测试.
可能更难维护.这在很大程度上取决于您的维护和编码实践.

However, a web service is in general slower and is dependent on an internet connection.
It's in general harder to test than a code library.
It may be harder to maintain. Much of that depends on your maintainance and coding practices.

如果需要上述功能中的几个或至少其中一个,我会考虑使用 Web 服务被认为是最重要的,缺点是可以接受的或必要的邪恶.

I would consider a web service if several of the above features are desired or at least one of them is considered paramount and the downsides were acceptable or a necessary evil.

共享库怎么样?

如果您更能控制"您的环境或想要成为什么样的人呢?你知道谁将使用代码(接口不是维护的问题),您不必担心互操作.您处于以下情况您可以轻松实现共享,而无需进行大量工作/障碍.

What if you are far more in "control" of your environment or want to be? You know who will be using the code (interface isn't a problem to maintain), you don't have to worry about interop. You are in a situation where you can easily achieve sharing without a lot of work / hoops to jump through.

我认为何时使用的示例:

Examples in my mind of when to use:

您可以控制许多应用程序,它们都托管在将使用该库的同一台或两台服务器上.

You have many applications in your control all hosted on the same server or two that will use the library.

不是很好的例子,您有许多应用程序,但都托管在十几个左右的服务器上.Web Service 可能是更好的选择.

Not so good example, you have many applications but all hosted on a dozen or so servers. Web Service may be a better choice.

您不确定可以使用谁或如何使用您的代码,但知道它对许多人来说很有价值.网络服务.

You are not sure who or how your code could be used but know it is of good value to many. Web Service.

您正在编写仅由一组有限的应用程序使用的东西,也许是一些辅助函数.图书馆.

You are writing something only used by a limited set of applications, perhaps some helper functions. Library.

你正在写一些高度专业化的东西,不适合很多人使用.例如您的业务线的 API其他人永远不会使用的应用程序.图书馆.

You are writing something highly specialized and is not suited for consumption by many. Such as an API for your Line of Business Application that no one else will ever use. Library.

如果所有条件都相同,从共享库开始并将其转变为 Web 服务会更容易,但反之则不然.

If all things being equal, it would be easier to start with a shared library and turn it into a web service but not so much vice versa.

还有很多,但这些是我的一些想法......

There are many more but these are some of my thoughts on it...

这篇关于Web 服务与共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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