简体   繁体   English

Web 服务与 Web 应用程序

[英]Web Service vs Web Application

I know this is an old question and must have been answered hundred times already, but I am not able to find a satisfactory response as yet.我知道这是一个老问题,肯定已经回答了数百次,但我还没有找到满意的答案。

I am creating an application which will be used by other applications (mobile/ web) to fetch the data.我正在创建一个应用程序,其他应用程序(移动/网络)将使用该应用程序来获取数据。 Now I have 2 options:现在我有两个选择:

  1. Create my application as a simple web application.将我的应用程序创建为一个简单的 Web 应用程序。
  2. Create a web service.创建一个网络服务。

A web service looks more sophisticated where any client will provide the data in a specified format (SOAP/ REST) and my app will parse the request and return the data asked by client. Web 服务看起来更复杂,其中任何客户端都将以指定格式 (SOAP/REST) 提供数据,我的应用程序将解析请求并返回客户端询问的数据。 How the data will be used is not my app's problem.如何使用数据不是我的应用程序的问题。

My question is that same can be achieved by a simple web app accepting the request in XML format and responding with an XML response.我的问题是,同样可以通过一个简单的 Web 应用程序接受 XML 格式的请求并以 XML 响应进行响应来实现。 Gut feeling is that a web service will be a better way to go for this kind of service where we are not sure who all will be using it.直觉是,在我们不确定谁会使用它的情况下,Web 服务将是实现这种服务的更好方式。 But are there any specific advantages of using a web service over a simple web app?但是,与简单的 Web 应用程序相比,使用 Web 服务有什么特别的优势吗?

If we think the terminology, which I think is the main question here.如果我们考虑术语,我认为这是这里的主要问题。

Web service refers to software, that serves data in any format (XML/JSON etc.) through some kind of web interface. Web 服务是指通过某种 Web 界面提供任何格式(XML/JSON 等)数据的软件。 That interface can be called API (Application Programming Interface).该接口可以称为 API(应用程序编程接口)。 REST and SOAP are ways to design the API. REST 和 SOAP 是设计 API 的方法。

Application is the software that is using this API provided by the web service.应用程序是使用 Web 服务提供的此 API 的软件。

In the other words, web service is "server" and application is "client".换句话说,Web 服务是“服务器”,应用程序是“客户端”。 Usually server serves machines and clients serve the user.通常服务器为机器服务,客户端为用户服务。

So in any way you choose to build your system, I would call the part that serves the data as "Web service" and the part that utilizes the data as "application" (or "web application" if such).因此,无论您选择以何种方式构建系统,我都会将提供数据的部分称为“Web 服务”,将利用数据的部分称为“应用程序”(或“Web 应用程序”,如果是这样的话)。

Sounds like in your case, you are building a web service that provides XML-formatted data for multiple applications.听起来像您的情况,您正在构建一个为多个应用程序提供 XML 格式数据的 Web 服务。 So my answer is: build the thing you are already building and call it web service .所以我的回答是:构建你已经构建的东西,并称之为web service

If your application doesn't need a user interface, then make it a web service.如果您的应用程序不需要用户界面,则将其设为 Web 服务。 If it needs a user interface, then use a web application.如果它需要用户界面,则使用 Web 应用程序。

At a low level web applications and web services are kinda the same thing.在底层,Web 应用程序和 Web 服务是一回事。 They both operatate over http(s).它们都通过 http(s) 运行。 SOAP is just a well defined version of XML. SOAP 只是一个定义良好的 XML 版本。 REST is kinda just HTTP. REST 有点像 HTTP。 If you wanted to, you could make a web application look like web services and visa versa.如果您愿意,您可以使 Web 应用程序看起来像 Web 服务,反之亦然。

The main difference would be internal development options based on the platform you are using.主要区别在于基于您使用的平台的内部开发选项。 If, for example, you are using Visual Studio then adding a WCF Service Application will give you a project which is by default geared towards WCF.例如,如果您使用的是 Visual Studio,那么添加 WCF 服务应用程序将为您提供一个默认面向 WCF 的项目。 But choosing any other application type won't stop you from adding Web Services.但是选择任何其他应用程序类型不会阻止您添加 Web 服务。

Using SOAP is generally a better option than plain old xml for these reasons:由于以下原因,使用 SOAP 通常比普通的旧 xml 更好:

  • Your users will be expecting it, and are likely to know how to read it already.您的用户会期待它,并且可能已经知道如何阅读它。

  • Your users' development environments will likely know all about SOAP and be able to interpret it out of the box.您的用户的开发环境可能了解所有关于 SOAP 的信息,并且能够开箱即用地解释它。 (If you provide a WSDL file then many users will be able to use a script to generate your classes in seconds.) (如果您提供 WSDL 文件,那么许多用户将能够使用脚本在几秒钟内生成您的类。)

  • Your messages are more likely to be well defined.您的消息更有可能得到明确定义。 I am working on a project at the moment where the other side have defined their own random XML structure and it is a nightmare to work with.我正在做一个项目,对方已经定义了他们自己的随机 XML 结构,这是一场噩梦。 I never really know what to expect, and there is little consistency between their different message types.我从来不知道会发生什么,而且它们不同的消息类型之间几乎没有一致性。 At least if they had agreed to conform to SOAP then I might have had a much easier time interpreting their messages.至少如果他们同意遵守 SOAP,那么我可能会更容易解释他们的消息。

My question is that same can be achieved by a simple web app accepting the request in XML format and responding with an XML response.我的问题是,同样可以通过一个简单的 Web 应用程序接受 XML 格式的请求并以 XML 响应进行响应来实现。

That is a web service.那是一个网络服务。 I think this is an issue of terminology.我认为这是一个术语问题。 You have no way of solving this other than to use a web service, whether it is restful or SOAP based is up to you but if you are passing data to clients in XML format, in response to XML requests, that is a web service.除了使用 Web 服务之外,您没有其他办法解决这个问题,它是 Restful 还是基于 SOAP 取决于您,但是如果您以 XML 格式将数据传递给客户端,以响应 XML 请求,那就是 Web 服务。

I suspect what you mean to ask is whether or not you should be using a RESTful webservice or a complicated SOAP based approach.我怀疑您想问的是您是否应该使用 RESTful Web 服务或复杂的基于 SOAP 的方法。 For me the answer depends on how many functions are needed in your 'Service'.对我来说,答案取决于您的“服务”中需要多少功能。

SOAP肥皂

If your service has lots of functions than users of java and/or visual studio would prefer to import your WSDL file and use your service as an object with all of the XML parsing done for them, so SOAP would be the answer.如果您的服务比 java 和/或 Visual Studio 的用户更愿意导入您的 WSDL 文件并将您的服务用作对象,并为它们完成所有 XML 解析,那么如果您的服务具有许多功能,那么 SOAP 将是答案。

REST休息

If you only have a few functions, with very basic input parameters and response data, then SOAP might be overkill.如果您只有几个函数,以及非常基本的输入参数和响应数据,那么 SOAP 可能有点过头了。

MySite.com/Add/5/3

or要么

MySite.com/GetStockSymbol/Facebook

or要么

MySite.com/GetWeather/Paris/France

I think this might help you in resolving your confusion我认为这可能会帮助您解决您的困惑

There are two main use cases of WEB in the industry WEB在业界主要有两个用例

  1. Business to Consumer(B2C) : Whenever there is consumer directly interacting with the business for its needs we always uses a Web-Application to provide a communication between two parties.企业对消费者(B2C):每当有消费者直接与其需求进行交互时,我们总是使用 Web 应用程序来提供两方之间的通信。
  2. Business to Business(B2B) : It means one part of the business need some input/services from another part of the business.企业对企业(B2B):这意味着业务的一部分需要来自另一部分业务的一些输入/服务。 Always a Web-Service is used to meet the business to business requirements.始终使用 Web 服务来满足企业对企业的需求。 Usually a consumer never interact with the Web-Services directly we only interacts with a Web-Application and a Web-Application interact with a Web-Services for information/data or processing.通常消费者从不直接与 Web 服务交互,我们只与 Web 应用程序交互,而 Web 应用程序与 Web 服务交互以获取信息/数据或处理。

Taken from http://coder2design.com/java-interview-questions/取自http://coder2design.com/java-interview-questions/

I asked this question more than 3 yeas back and a lot of water has flowed under the bridge since then. 3 年前我问过这个问题,从那时起,桥下流了很多水。 I have worked on tens of web applications and created hundreds of web services.我曾开发过数十个 Web 应用程序并创建了数百个 Web 服务。 So I guess it makes sense to answer my own question here.所以我想在这里回答我自己的问题是有意义的。

The challenge which I faced when I asked this question was that I got confused between the terms application and service (note that web is common element in web application and web service).当我问这个问题时,我面临的挑战是我对应用程序和服务这两个术语感到困惑(请注意,Web 是 Web 应用程序和 Web 服务中的常见元素)。 As the name would suggest, application is an application in itself, whereas a service is meant to serve others.顾名思义,应用程序本身就是一个应用程序,而服务旨在为其他人服务。 A service probably has no meaning unless someone is going to use it.服务可能没有意义,除非有人要使用它。 It can serve one or more applications or services.它可以为一个或多个应用程序或服务提供服务。

Now if I look at my question现在如果我看我的问题

I am creating an application which will be used by other applications (mobile/ web) to fetch the data.我正在创建一个应用程序,其他应用程序(移动/网络)将使用该应用程序来获取数据。 Now I have 2 options, 1. to create my application as a simple web application 2. To create a web service.现在我有 2 个选项,1. 将我的应用程序创建为一个简单的 Web 应用程序 2. 创建一个 Web 服务。

I would like to tell myself that "Dude! if there is an entity which takes a request and returns data, you are talking about a service."我想告诉自己:“老兄!如果有一个实体接受请求并返回数据,那么您就是在谈论服务。” Because I am not worried about what is going to happen with that data?因为我不担心这些数据会发生什么? Who will use it?谁会使用它? How will that be displayed?那将如何显示?

I am taking a request and returning data.我正在接受请求并返回数据。 Now how am I doing that is part of implementation.现在我如何做这是实施的一部分。 I might use SOAP or REST.我可能会使用 SOAP 或 REST。 I might use Jersey or Spring MVC/ REST or may be a simple servlet which takes a request and returns data in JSON or XML or String or any other required format.我可能会使用 Jersey 或 Spring MVC/REST,或者可能是一个简单的 servlet,它接受请求并以 JSON 或 XML 或字符串或任何其他所需格式返回数据。

From RESTful Web Services by Leonard Richardson and Sam Ruby, ISBN: 978-0-596-52926-0:来自 Leonard Richardson 和 Sam Ruby 的RESTful Web 服务,ISBN:978-0-596-52926-0:

Web services are indeed very similar to web applications, but resource creation is one of the places where they differ. Web 服务确实与 Web 应用程序非常相似,但资源创建是它们不同的地方之一。 The main difference here is that HTML forms currently support only GET and POST.这里的主要区别在于 HTML 表单目前仅支持 GET 和 POST。 This means web applications must use overloaded POST to convey any unsafe operation.这意味着 Web 应用程序必须使用过载的 POST 来传达任何不安全的操作。

Web services dont always have a UI. Web 服务并不总是有 UI。 They are normally API's using JSON, can also be SOA type using SOAP and XML primarily, can also be sockets, and servers and other micro web services, etc..它们通常是使用 JSON 的 API,也可以是主要使用 SOAP 和 XML 的 SOA 类型,也可以是套接字、服务器和其他微 Web 服务等。

Web applications can be put together many ways. Web 应用程序可以通过多种方式组合在一起。 There are several ways to create your application by orchestration of multiple web services, and a separate gui to control them which ties into these services.有多种方法可以通过编排多个 Web 服务来创建您的应用程序,并使用单独的 gui 来控制它们与这些服务的联系。 The other way which does not use services is to procedurally embed code into your UI interface app, or even better, make an Object Oriented application which has its own services separed in the Model later, which the controller access, and has its own view as a GUI which access the services in the back end, or even more complicated apps that pass A2B, B2B, B2C services from some GUI.不使用服务的另一种方法是将代码按程序嵌入到您的 UI 界面应用程序中,或者甚至更好的是,创建一个面向对象的应用程序,该应用程序稍后在模型中分离出自己的服务,控制器访问该应用程序,并拥有自己的视图作为一个访问后端服务的 GUI,或者甚至更复杂的应用程序,它从某个 GUI 传递 A2B、B2B、B2C 服务。

Services dont always have a GUI, they can have a CRUD to maintain the data, but once you start to have these types of features, it becomes an application in its own right.服务并不总是有一个 GUI,它们可以有一个 CRUD 来维护数据,但是一旦你开始拥有这些类型的特性,它就变成了一个独立的应用程序。 The services are applied to something greater than themselves.这些服务应用于比它们更重要的东西。 this applying creates your application.此应用程序创建您的应用程序。 It has to have a purpose.它必须有一个目的。 Normally it takes more than one blind service to complete your applicatoin, and there is some kind of interface.通常需要多个盲服务来完成您的申请,并且有某种接口。

If you just blindly send a uri request to your service, and it blindly sends back json, that's a service.如果您只是盲目地向您的服务发送 uri 请求,而它又盲目地发回 json,那就是服务。 Whats blindly sending this?什么瞎送这个? If you, then not an application.如果你,那么不是一个应用程序。 If some sort of crud, then its becoming an application, the crud is a GUI for accessing the services, and as a whole, its a data management application system.如果是某种 crud,那么它就变成了一个应用程序,这个 crud 是一个用于访问服务的 GUI,作为一个整体,它是一个数据管理应用程序系统。 Now if you put a layer on the front to demonstrate this data in website fashion, you now have a product to display this data, a product to manage it, and the data which is the real product, and which is accessible via the web service, its now a full on application.现在,如果您在前面放置一层以网站方式展示这些数据,那么您现在有一个产品来显示这些数据,一个产品来管理它,以及这些数据是真正的产品,并且可以通过 Web 服务访问,它现在是一个完整的应用程序。 Your endeavour at creating this becomes your application.您在创建此方面的努力将成为您的应用程序。

I know its too late to replay, but still i want我知道重播为时已晚,但我仍然想要

Web Services approach is good if Web 服务方法是好的,如果

a.一种。 enterprise integration with only webservices, like integrating distributed modules /applications.仅与 Web 服务的企业集成,例如集成分布式模块/应用程序。

b.suited for distributed applications适合分布式应用

c. C。 more than one consumer for same service - like Banks consuming data from Credit Reporting Agency同一服务的多个消费者 - 例如银行消费来自信用报告机构的数据

d. d. consumers want data in different formats - like one consumer(customer) wants in XML format, other would be in JASON ..etc消费者需要不同格式的数据 - 比如一个消费者(客户)需要 XML 格式,其他人需要 JASON ..etc

I guess the web application vs web service is the fact that the deployment factor ratio vary meaning the deployment of a web application would be limited (locally ) to what as in case of a web service (globally).我猜 Web 应用程序与 Web 服务的事实是部署因子比率不同,这意味着 Web 应用程序的部署将(本地)限制为 Web 服务(全局)的情况。 Plus, When we think of UI perspective better option is the Web application but when we think of programming and data transfer perspective mainly go for a web service.另外,当我们想到 UI 透视图时,更好的选择是 Web 应用程序,但是当我们想到编程和数据传输透视图时,主要选择 Web 服务。 Web application requires use of servlets with frameworks like Spring mvc etc. On the other hand, if you want to deploy the same application to multiple platforms make it a web service via Rest/Soap implementations so that the web applications behaviour gets changed to rather a service. Web 应用程序需要使用带有 Spring mvc 等框架的 servlet。另一方面,如果您想将相同的应用程序部署到多个平台,请通过 Rest/Soap 实现将其作为 Web 服务,以便 Web 应用程序的行为变为服务。

In short,简而言之,

   WebService   =

                 (RestApi/Soap)    # added 
             /         |         \
(client1)---(Web Application)---(clientN)

This is a simple way to know about it:这是了解它的简单方法:

Web Application means for human beign can read. Web 应用程序意味着人类可以阅读。 it is accessed through browsers.它是通过浏览器访问的。

Whereas然而

Web Services means for computers can read. Web Services意味着计算机可以读取。 it is accessed from any languages or platform.它可以从任何语言或平台访问。

For example:例如:

Yatra.com (Java based services) application communicate Paypal.com (Python based services) application Yatra.com (基于 Java 的服务)应用程序与Paypal.com (基于 Python 的服务)应用程序通信

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM