Java EE 7 教程 第一部分 简介 第1章 概述 第1.5节 Web服务支持

原文:http://docs.oracle.com/javaee/7/tutorial/doc/overview005.htm
翻译:石卓林 shizhuolin@hotmail.com

1.5 Web Services Support

Web services are web-based enterprise applications that use open, XML-based standards and transport protocols to exchange data with calling clients. The Java EE platform provides the XML APIs and tools you need to quickly design, develop, test, and deploy web services and clients that fully interoperate with other web services and clients running on Java-based or non-Java-based platforms.

To write web services and clients with the Java EE XML APIs, all you do is pass parameter data to the method calls and process the data returned; for document-oriented web services, you send documents containing the service data back and forth. No low-level programming is needed, because the XML API implementations do the work of translating the application data to and from an XML-based data stream that is sent over the standardized XML-based transport protocols. These XML-based standards and protocols are introduced in the following sections.

The translation of data to a standardized XML-based data stream is what makes web services and clients written with the Java EE XML APIs fully interoperable. This does not necessarily mean that the data being transported includes XML tags, because the transported data can itself be plain text, XML data, or any kind of binary data, such as audio, video, maps, program files, computer-aided design (CAD) documents, and the like. The next section introduces XML and explains how parties doing business can use XML tags and schemas to exchange data in a meaningful way.

1.5 Web服务支持

Web服务是基于web的企业应用, 它使用开放的,基于XML的标准和传输协议,用于客户端调用时交换数据. Java EE平台提供XML API和你需要的用于快速设计,开发,测试和部署web服务和客户端的工具, 它完全满足其它基于Java或非Java平台的Web服务和客户端交互需求.

通过Java EE XML APIs编写web服务和客户端,你要做的就是传递参数到调用方法并且处理返回数据;对于面向文档的web服务,你发送包含来回服务数据的文档. 没有必要做底层编程.因为XML API实现了应用数据转换为基于XML的数据流的功能和基于XML的标准传输协议.基于XML的标准和协议在下面章节介绍.

转换数据为标准化的基于XML的数据流,这在通过Java EE XML APIs编写的Web服务和客户端上是完全兼容的. 这并不意味着被传送的数据包括XML标记,因为被传输的数据本身可以是纯文本或者任何类型的二进制数据,如音频,视频,地图,程序文件,计算机辅助设计(CAD)的文件,等等. 下一章介绍XML和解释如何把XML标签和架构用于有意义的数据交换业务.

1.5.1 XML

Extensible Markup Language (XML) is a cross-platform, extensible, text-based standard for representing data. Parties that exchange XML data can create their own tags to describe the data, set up schemas to specify which tags can be used in a particular kind of XML document, and use XML style sheets to manage the display and handling of the data.

For example, a web service can use XML and a schema to produce price lists, and companies that receive the price lists and schema can have their own style sheets to handle the data in a way that best suits their needs. Here are examples.

  • One company might put XML pricing information through a program to translate the XML to HTML so that it can post the price lists to its intranet.
  • A partner company might put the XML pricing information through a tool to create a marketing presentation.
  • Another company might read the XML pricing information into an application for processing.

1.5.1 XML

可扩展标记语言(XML)是一个跨平台的,可扩展的,基于文本的数据描述标准. 各方交换数据时可以创建他们自己的标签用于描述数据, 设置架构规定那些标签可以在特定类型XML文档中使用.并且使用XML样式表来管理数据的显示和处理.

例如,一个web服务可以使用XML和架构产生价格列表, 接收价格表和架构的厂商可以用他们自己的样式表以最适合他们需要的方式处理数据. 下面有些示例:

  • 一个公司可能通过程序把XML格式的定价信息从XML转换为HTML, 这样他们就可以在内部网络张贴价格表.
  • 一个合作公司可能通过工具把xml格式的定价信息创建为营销演示.
  • 其他公司可能读取XML格式的定价信息到用于处理的应用程序.

1.5.2 SOAP Transport Protocol

Client requests and web service responses are transmitted as Simple Object Access Protocol (SOAP) messages over HTTP to enable a completely interoperable exchange between clients and web services, all running on different platforms and at various locations on the Internet. HTTP is a familiar request-and-response standard for sending messages over the Internet, and SOAP is an XML-based protocol that follows the HTTP request-and-response model.

The SOAP portion of a transported message does the following:

  • Defines an XML-based envelope to describe what is in the message and explain how to process the message
  • Includes XML-based encoding rules to express instances of application-defined data types within the message
  • Defines an XML-based convention for representing the request to the remote service and the resulting response

1.5.2 SOAP 传输协议

使用简单对象访问协议(SOAP)传输客户端请求和web服务的响应消息, 通过HTTP使客户端与在互联网不同的位置和不同平台上运行的WEB服务实现完全互通交流. HTTP是一种通过互联网发送消息的 “请求-响应” 标准. SOAP基于XML协议,它遵循HTTP的 “请求-响应” 模型.

一个传送消息的SOAP部分需要做以下工作:

  • 定义基于XML架构描述些什么消息.并且解释如何处理消息.
  • 包含基于XML编码规则表达的应用定义的数据类型实例.
  • 定义一个表述请求远程服务和相应结果的基于XML的规范

1.5.3 WSDL Standard Format

The Web Services Description Language (WSDL) is a standardized XML format for describing network services. The description includes the name of the service, the location of the service, and ways to communicate with the service. WSDL service descriptions can be published on the Web. GlassFish Server provides a tool for generating the WSDL specification of a web service that uses remote procedure calls to communicate with clients.

1.5.3 WSDL 标准格式

WEB服务描述语言(WSDL)是一个描述网络服务的标准XML格式. 它描述了服务名称,服务位置,如何与服务通讯. WSDL服务可以在网络上公开.GlassFish服务器提供了生成用于客户端远程调用WEB服务通讯的WSDL规范的工具调用.

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.

Proudly powered by WordPress   Premium Style Theme by www.gopiplus.com
渝公网安渝公网安备 50010702500270号 渝ICP备09056628号-7