译-Web Service剖析: 使用XML, SOAP 和WSDL 进行独立于平台的数据交换

Most applications are developed to interact with users; the user enters or searches for data through an interface and the application then responds to the user‘s input. A Web service does more or less the same thing except that a Web service application communicates only from machine to machine or application to application. There is often no direct user interaction. A Web service basically is a collection of open protocols that is used to exchange data between applications. The use of open protocols enables Web services to be platform independent. Software that are written in different programming languages and that run on different platforms can use Web services to exchange data over computer networks such as the Internet. In other words, Windows applications can talk to PHP, Java and Perl applications and many others, which in normal circumstances would not be possible.

How Do Web Services Work?

Because different applications are written in different programming languages, they often cannot communicate with each other. A Web service enables this communication by using a combination of open protocols and standards, chiefly XML, SOAP and WSDL. A Web service uses XML to tag data, SOAP to transfer a message and finally WSDL to describe the availability of services. Let‘s take a look at these three main components of a Web service application.

Simple Object Access Protocol (SOAP)

The Simple Object Access Protocol or SOAP is a protocol for sending and receiving messages between applications without confronting interoperability issues (interoperability meaning the platform that a Web service is running on becomes irrelevant). Another protocol that has a similar function is HTTP. It is used to access Web pages or to surf the Net. HTTP ensures that you do not have to worry about what kind of Web server -- whether Apache or IIS or any other -- serves you the pages you are viewing or whether the pages you view were created in ASP.NET or HTML. Because SOAP is used both for requesting and responding, its contents vary slightly depending on its purpose. Below is an example of a SOAP request and response message:

SOAP Request:

POST /InStock HTTP/1.1
Host: www.bookshop.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
    <soap:Body xmlns:m="http://www.bookshop.org/prices">
        <m:GetBookPrice>
            <m:BookName>The Fleamarket</m:BookName>
        </m:GetBookPrice>
    </soap:Body>
</soap:Envelope>

SOAP Response:

POST /InStock HTTP/1.1
Host: www.bookshop.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
    <soap:Body xmlns:m="http://www.bookshop.org/prices">
        <m:GetBookPriceResponse>
            <m: Price="">10.95</m:>
        </m:GetBookPriceResponse>
    </soap:Body>
</soap:Envelope>

Although both messages look the same, they carry out different methods. For instance looking at the above examples you can see that the requesting message uses the GetBookPrice method to get the book price. The response is carried out by the getbookpriceResponse method, which is going to be the message that you as the "requestor" will see. You can also see that the messages are composed using XML.

Web Services Description Language or WSDL

How do you know what methods are available in a Web service that you stumble across on the Internet? Well, WSDL takes care of that for you. WSDL is a document that describes a Web service and also tells you how to access and use its methods. Take a look at a sample WSDL file:

<?xml version="1.0" encoding="utf-8"?>
<definitions name="DayOfWeek" targetNamespace="http://www.roguewave.com/soapworx/examples/DayOfWeek.wsdl" xmlns:tns="http://www.roguewave.com/soapworx/examples/DayOfWeek.wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="DayOfWeekInput">
    <part name="date" type="xsd:date" />
</message>
<message name="DayOfWeekResponse">
    <part name="dayOfWeek" type="xsd:string" />
</message>
<portType name="DayOfWeekPortType">
    <operation name="GetDayOfWeek">
        <input message="tns:DayOfWeekInput" />
        <output message="tns:DayOfWeekResponse" />
    </operation>
</portType>
<binding name="DayOfWeekBinding" type="tns:DayOfWeekPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
    <operation name="GetDayOfWeek">
        <soap:operation soapAction="getdayofweek" />
        <input>
            <soap:body use="encoded" namespace="http://www.roguewave.com/soapworx/examples" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
        </input>
        <output>
            <soap:body use="encoded" namespace="http://www.roguewave.com/soapworx/examples" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
        </output>
    </operation>
</binding>
<service name="DayOfWeekService">
<documentation>Returns the day-of-week name for a given date 40</documentation>41
<port name="DayOfWeekPort" binding="tns:DayOfWeekBinding">42
<soap:address location="http://localhost:8090/dayofweek/DayOfWeek" />43</port>44</service>45</definitions>

The main things to remember about a WSDL file are that it provides you with:

  • A description of a Web service
  • The methods a Web service uses and the parameters that it takes
  • A way to locate Web services

原文参见:

Anatomy of a Web Service: XML, SOAP and WSDL for Platform-independent Data Exchange

时间: 2024-08-09 14:22:48

译-Web Service剖析: 使用XML, SOAP 和WSDL 进行独立于平台的数据交换的相关文章

XML Web Service:HTTP-GET, HTTP-POST and SOAP的比较

XML Web Service:HTTP-GET, HTTP-POST and SOAP的比较 XML Web Service支持三种协议来与用户交流数据.这三种协议分别是: 1. SOAP:Simple Object Access Protocol 2.  HTTP-GET 3.   HTTP-POST 1.首先我们先来理解一下这三者的大概定义. 在这三种协议中,SOAP是XML Web Service最常用到的连接协议.与HTTP相比,SOAP显的更为复杂,但却拥有更强的接受能力.SOAP是

Web Service笔记(三):wsdl 与 soap协议详解

注:1.结合Web Service笔记(二):利用CXF开发Web Service 一.WSDL语言:(web service definition language - web service定义语言) (一)简介: 1.wsdl 是全完基于xml 的,特别是xml schema.详见: XML学习笔记(三):XML规范:Schema详解. 2.wsdl 文档描述了 ws 主要的3个方面: 1)WHATA:该 ws 包含"什么"操作,即有几个方法. 2)HOW:该 ws 的操作应该&

MyEclipse 2013 Web Service 实现以xml格式数据传递

提示:由于版本问题,使用MyEclipse 2013web Service的框架只有JAX-WS和JAX-RS,就没有XFire这个框架了....个人觉得XFire不怎么好用 一,新建一个服务器端的Web Service Project项目 2,我的xml数据是从数据库中来的,所有在生成xml之前,要连接数据库查询出来放在集合里...这些过程码农们自己写咯.... 这个是查询出,生成xml格式数据的.... 3,最重要的发布service 4,现在就把你的项目发布到tomcat中,不过咧...肯

web Service 接口对xml数据处理

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Xml; using IM.BLL; using IM.Model; using System.IO; using System.Text; using WebSite.Public.FlashUpload; namespace WebSite.Ap

Android笔记之 Web Service 基础

一.Web Service是什么? 就是网络服务,根据W3C的定义,WebServices(Web服务)是一个用于支持网络间不同机器互操作的软件系统,它是一种自包含.自描述和模块化的应用程序,它可以在网络中被描述.发布和调用,可以将它看作是基于网络的.分布式的模块化组件.  Web Services是建立在通用协议的基础之上的,包括HTTP.SOAP.UDDI.WSDL等.其中Web Service三要素就是SOAP.WSDL和UDDI. SOAP用来描述传递信息的格式, WSDL用来描述如何访

XML应用之Web Service

1.什么是web service? Service:服务,在电脑安装一个软件(程序),可以为我们提供某些功能,就可以称之为服务.本地服务比较多. Web:和本地相对应,在互联网上的. Web Service,通过互联网来提供某种服务,本质就是通过网络调用其他网站的资源. 本地服务的缺陷: (1) 本地资源不足:很多数据和资料,本地得不到,只有向其他网站要. (2)成本因素:本地提供服务,往往是不经济的,使用专业网站的服务更便宜. (3)可移植性差. Web Service的优势: (1)平台无关

web service,soap ,http,tcp,udp

webservice and soap  HTTP只负责把数据传送过去,不会管这个数据是XML.HTML.图片.文本文件或者别的什么.而SOAP协议则定义了怎么把一个对象变成XML文本,在远程如何调用等,怎么能够混为一谈.                 这样说两种协议:     HTTP就是邮局的协议,他们规定了你的信封要怎么写,要贴多少邮票等....         SOAP就是你们之间交流的协议,负责把你所需要表达的意思写在信纸上,同时也负责让对方能够看得懂你的信. Web service

Web service standards: SOAP, REST, OData, and more

Web service standards: SOAP, REST, OData, and more So far, we've covered the components of a web service, the messaging format and transport protocols. But in the eye of the developer, the development manager, and the IT professional,the real choice

Web Service简介

1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独立的通讯技术.是:通过SOAP在Web上提供的软件服务,使用WSDL文件进行说明,并通过UDDI进行注册. XML:(Extensible Markup Language)扩展型可标记语言.面向短期的临时数据处理.面向万维网络,是Soap的基础. Soap:(Simple Object A