Web 服务与 Web 应用程序 [英] Web Service vs Web Application

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

问题描述

我知道这是一个老问题,肯定已经回答了数百次,但我还没有找到满意的答案.

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. 将我的应用程序创建为一个简单的 Web 应用程序.
  2. 创建网络服务.

Web 服务看起来更复杂,其中任何客户端都将以指定格式 (SOAP/REST) 提供数据,我的应用程序将解析请求并返回客户端询问的数据.如何使用数据不是我应用的问题.

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. How the data will be used is not my app's problem.

我的问题是,同样可以通过一个简单的 Web 应用程序接受 XML 格式的请求并以 XML 响应进行响应来实现.直觉是,在我们不确定谁会使用它的情况下,Web 服务将是实现这种服务的更好方式.但是,与简单的网络应用相比,使用网络服务有什么特别的优势吗?

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. 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. But are there any specific advantages of using a web service over a simple web app?

推荐答案

在底层,Web 应用程序和 Web 服务是一回事.它们都通过 http(s) 运行.SOAP 只是一个定义良好的 XML 版本.REST 有点像 HTTP.如果您愿意,您可以使网络应用程序看起来像网络服务,反之亦然.

At a low level web applications and web services are kinda the same thing. They both operatate over http(s). SOAP is just a well defined version of XML. REST is kinda just HTTP. If you wanted to, you could make a web application look like web services and visa versa.

主要区别在于基于您使用的平台的内部开发选项.例如,如果您使用的是 Visual Studio,那么添加 WCF 服务应用程序将为您提供一个默认面向 WCF 的项目.但是选择任何其他应用程序类型都不会阻止您添加 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. But choosing any other application type won't stop you from adding Web Services.

出于以下原因,使用 SOAP 通常比普通的旧 xml 更好:

Using SOAP is generally a better option than plain old xml for these reasons:

  • 您的用户会期待它,并且可能已经知道如何阅读它.

  • Your users will be expecting it, and are likely to know how to read it already.

您的用户的开发环境可能了解所有关于 SOAP 的信息,并且能够开箱即用地解释它.(如果您提供 WSDL 文件,那么许多用户将能够使用脚本在几秒钟内生成您的类.)

Your users' development environments will likely know all about SOAP and be able to interpret it out of the box. (If you provide a WSDL file then many users will be able to use a script to generate your classes in seconds.)

您的消息更有可能得到明确定义.我正在做一个项目,对方已经定义了他们自己的随机 XML 结构,这是一场噩梦.我从来不知道会发生什么,而且它们不同的消息类型之间几乎没有一致性.至少,如果他们同意遵守 SOAP,那么我可能会更容易解释他们的消息.

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. 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.

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

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