简体   繁体   English

SOAP消息和WSDL之间的区别?

[英]Difference between a SOAP message and a WSDL?

I am confused about how SOAP messages and WSDL fit together? 我对SOAP消息和WSDL如何组合起来感到困惑? I have started looking into SOAP messages such as: 我已经开始研究SOAP消息,例如:

    POST /InStock HTTP/1.1
Host: www.example.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.example.org/stock">
  <m:GetStockPrice>
    <m:StockName>IBM</m:StockName>
  </m:GetStockPrice>
</soap:Body>

</soap:Envelope>

Are all SOAP messages WSDL's? 所有SOAP消息都是WSDL的吗? Is SOAP a protocol that accepts its own 'SOAP messages' or 'WSDL's? SOAP是一种接受自己的“SOAP消息”还是“WSDL”的协议? If they are different, then when should I use SOAP messages and when should I use WSDL's? 如果它们不同,那么我何时应该使用SOAP消息?何时应该使用WSDL?

Some clarification around this would be awesome. 对此的一些澄清将是非常棒的。

A SOAP document is sent per request. 每个请求都会发送一个SOAP文档。 Say we were a book store, and had a remote server we queried to learn the current price of a particular book. 假设我们是一家书店,并且我们查询了一台远程服务器,以了解特定书籍的当前价格。 Say we needed to pass the Book's title, number of pages and ISBN number to the server. 假设我们需要将书的标题,页数和ISBN号传递给服务器。

Whenever we wanted to know the price, we'd send a unique SOAP message. 每当我们想知道价格时,我们都会发送一条独特的SOAP消息。 It'd look something like this; 它看起来像这样;

<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <m:GetBookPrice xmlns:m="http://namespaces.my-example-book-info.com">
      <ISBN>978-0451524935</ISBN>
      <Title>1984</Title>
      <NumPages>328</NumPages>
    </m:GetBookPrice>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope> 

And we expect to get a SOAP response message back like; 我们希望得到一条SOAP响应消息;

<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <m:GetBookPriceResponse xmlns:m="http://namespaces.my-example-book-info.com">
      <CurrentPrice>8.99</CurrentPrice>
      <Currency>USD</Currency>
    </m:GetBookPriceResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The WSDL then describes how to handle/process this message when a server receives it. 然后,WSDL描述了当服务器接收到该消息时如何处理/处理该消息。 In our case, it describes what types the Title, NumPages & ISBN would be, whether we should expect a response from the GetBookPrice message and what that response should look like. 在我们的例子中,它描述了Title,NumPages和ISBN的类型,我们是否应该期望GetBookPrice消息的响应以及响应应该是什么样的。

The types would look like this; 类型看起来像这样;

<wsdl:types>

  <!-- all type declarations are in a chunk of xsd -->
  <xsd:schema targetNamespace="http://namespaces.my-example-book-info.com"
    xmlns:xsd="http://www.w3.org/1999/XMLSchema">

    <xsd:element name="GetBookPrice">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="ISBN" type="string"/>
          <xsd:element name="Title" type="string"/>
          <xsd:element name="NumPages" type="integer"/>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:element>

    <xsd:element name="GetBookPriceResponse">
      <xsd:complexType>
        <xsd:sequence>
          <xsd:element name="CurrentPrice" type="decimal" />
          <xsd:element name="Currency" type="string" />
        </xsd:sequence>
      </xsd:complexType>
    </xsd:element>

  </xsd:schema>
</wsdl:types>

But the WSDL also contains more information, about which functions link together to make operations, and what operations are avaliable in the service, and whereabouts on a network you can access the service/operations. 但是WSDL还包含更多信息,关于哪些功能链接在一起以进行操作,以及哪些操作可用于服务,以及网络上可以访问服务/操作的位置。

See also W3 Annotated WSDL Examples 另请参见W3带注释的WSDL示例

A SOAP message is a XML document which is used to transmit your data. SOAP消息是用于传输数据的XML文档。 WSDL is an XML document which describes how to connect and make requests to your web service. WSDL是一个XML文档,它描述了如何连接和向Web服务发出请求。

Basically SOAP messages are the data you transmit, WSDL tells you what you can do and how to make the calls. 基本上,SOAP消息是您传输的数据,WSDL告诉您可以执行的操作以及如何进行调用。

A quick search in Google will yield many sources for additional reading (previous book link now dead, to combat this will put any new recommendations in comments) 在Google中进行快速搜索会产生许多额外阅读资源(之前的图书链接现已死亡,为了解决此问题,我们会在评论中提出任何新建议)

Just noting your specific questions: 只是注意到你的具体问题:

Are all SOAP messages WSDL's? 所有SOAP消息都是WSDL的吗? No, they are not the same thing at all. 不,他们根本不是一回事。

Is SOAP a protocol that accepts its own 'SOAP messages' or 'WSDL's? SOAP是一种接受自己的“SOAP消息”还是“WSDL”的协议? No - reading required as this is far off. 不需要阅读,因为这远远不够。

If they are different, then when should I use SOAP messages and when should I use WSDL's? 如果它们不同,那么我何时应该使用SOAP消息?何时应该使用WSDL? Soap is structure you apply to your message/data for transfer. 肥皂是您应用于传输的消息/数据的结构。 WSDLs are used only to determine how to make calls to the service in the first place. WSDL仅用于确定如何首先调用服务。 Often this is a one time thing when you first add code to make a call to a particular webservice. 当您第一次添加代码来调用特定的Web服务时,这通常是一次性的事情。

A WSDL (Web Service Definition Language) is a meta-data file that describes the web service. WSDL(Web服务定义语言)是描述Web服务的元数据文件。

Things like operation name, parameters etc. 操作名称,参数等等

The soap messages are the actual payloads soap消息是实际的有效负载

We need to define what is a web service before telling what are the difference between the SOAP and WSDL where the two (SOAP and WSDL) are components of a web service 在告诉SOAP和WSDL之间有什么区别之前我们需要定义什么是Web服务,其中两个(SOAP和WSDL)是Web服务的组件

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. Web服务或多或少地做同样的事情,除了Web服务应用程序仅在机器之间或应用程序与应用程序之间进行通信。 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. Web服务基本上是一组开放协议,用于在应用程序之间交换数据。 The use of open protocols enables Web services to be platform independent. 使用开放协议使Web服务能够独立于平台。 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. 以不同编程语言编写并在不同平台上运行的软件可以使用Web服务通过诸如因特网之类的计算机网络交换数据。 In other words, Windows applications can talk to PHP, Java and Perl applications and many others, which in normal circumstances would not be possible. 换句话说,Windows应用程序可以与PHP,Java和Perl应用程序以及许多其他应用程序通信,这在正常情况下是不可能的。

How Do Web Services Work? Web服务如何工作?

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. Web服务通过结合使用开放协议和标准(主要是XML,SOAP和WSDL)来实现此通信。 A Web service uses XML to tag data, SOAP to transfer a message and finally WSDL to describe the availability of services. Web服务使用XML来标记数据,使用SOAP来传输消息,最后使用WSDL来描述服务的可用性。 Let's take a look at these three main components of a Web service application. 我们来看看Web服务应用程序的这三个主要组件。

Simple Object Access Protocol (SOAP) 简单对象访问协议(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). 简单对象访问协议或SOAP是用于在应用程序之间发送和接收消息而不会遇到互操作性问题的协议(互操作性意味着运行Web服务的平台变得无关紧要)。 Another protocol that has a similar function is HTTP. 另一种具有类似功能的协议是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. HTTP确保您不必担心哪种Web服务器(无论是Apache还是IIS或其他任何服务器)为您查看的页面提供服务,或者您查看的页面是否是用ASP.NET或HTML创建的。

Because SOAP is used both for requesting and responding, its contents vary slightly depending on its purpose. 因为SOAP既用于请求又用于响应,因此其内容根据其用途略有不同。

Below is an example of a SOAP request and response message 下面是SOAP请求和响应消息的示例

SOAP Request: SOAP请求:

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: SOAP响应:

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: Price> 
    </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. 例如,查看上面的示例,您可以看到请求消息使用GetBookPrice方法来获取图书价格。 The response is carried out by the GetBookPriceResponse method, which is going to be the message that you as the "requestor" will see. 响应由GetBookPriceResponse方法执行,该方法将成为您作为“请求者”将看到的消息。 You can also see that the messages are composed using XML. 您还可以看到消息是使用XML组成的。

Web Services Description Language or WSDL Web服务描述语言或WSDL

WSDL is a document that describes a Web service and also tells you how to access and use its methods. WSDL是一个描述Web服务的文档,还告诉您如何访问和使用它的方法。

WSDL takes care of how do you know what methods are available in a Web service that you stumble across on the Internet. WSDL负责了解您如何知道在Internet上偶然发现的Web服务中可用的方法。

Take a look at a sample WSDL file: 看一下示例WSDL文件:

<?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 
    </documentation> 
    <port name="DayOfWeekPort" binding="tns:DayOfWeekBinding"> 
      <soap:address location="http://localhost:8090/dayofweek/DayOfWeek"/> 
    </port> 
  </service> 
</definitions> 

The main things to remember about a WSDL file are that it provides you with: 关于WSDL文件要记住的主要事项是它为您提供:

  • A description of a Web service Web服务的描述

  • The methods a Web service uses and the parameters that it takes Web服务使用的方法及其所采用的参数

  • A way to locate Web services 一种定位Web服务的方法

  • Better analogy than the telephone call: Ordering products via postal mail from a mail-order service. 比电话更好的比喻:通过邮购服务邮寄订购产品。 The WSDL document is like the instructions that explain how to create the kind of order forms that the service provider will accept. WSDL文档就像解释如何创建服务提供者将接受的订单表单的说明。 A SOAP message is like an envelope with a standard design (size, shape, construction) that every post office around the world knows how to handle. SOAP消息就像一个标准设计(大小,形状,结构)的信封,世界各地的邮局都知道如何处理。 You put your order form into such an envelope. 您将订单放入这样的信封中。 The network (eg the internet) is the postal service. 网络(例如互联网)是邮政服务。 You put your envelope into the mail. 你把信封放进邮件里。 The employees of the postal service do not look inside the envelope. 邮政服务的员工不看信封。 The payload XML is the order form that you have enclosed in the envelope. 有效负载XML是您在信封中附带的订单。 After the post office delivers the envelope, the web service provider opens the envelope and processes the order form. 在邮局递送信封后,Web服务提供商打开信封并处理订单。 If you have created and filled out the form correctly, they will mail the product that you ordered back to you. 如果您已正确创建并填写表单,他们会将您订购的产品邮寄给您。

    In a simple terms if you have a web service of calculator. 简单来说,如果您有计算器的Web服务。 WSDL tells about the functions that you can implement or exposed to the client. WSDL讲述了您可以实现或向客户端公开的函数。 For example: add, delete, subtract and so on. 例如:添加,删除,减去等。 Where as using SOAP you actually perform actions like doDelete(), doSubtract(), doAdd(). 在使用SOAP的情况下,您实际执行doDelete(),doSubtract(),doAdd()等操作。 So SOAP and WSDL are apples and oranges. 所以SOAP和WSDL是苹果和橘子。 We should not compare them. 我们不应该比较它们。 They both have their own different functionality. 它们都有自己不同的功能。

    SOAP : It's an open standard XML based Communication protocol which is used to exchange information from the user to web service or vice versa. SOAP:它是一种开放的标准XML通信协议,用于将信息从用户交换到Web服务,反之亦然。 The soap is just the document in which the data are organized in some Manner. soap只是以某种方式组织数据的文档。 For every request and response separate soap may be present. 对于每个请求和响应,可能存在单独的肥皂。

    WSDL: In soap the data are organized in some manner and this organization is specified in WSDL, The data type which has to be used are also specified here. WSDL:在soap中,数据以某种方式组织,并且此组织在WSDL中指定,此处还指定了必须使用的数据类型。 For request and response single WSDL will be present 对于请求和响应,将存在单个WSDL

    The WSDL is a kind of contract between API provider and the client it's describe the web service : the public function , optional/required field ... WSDL是API提供者和客户端之间的一种合约,它描述了Web服务:公共功能,可选/必填字段......

    But The soap message is a data transferred between client and provider (payload) 但肥皂消息是客户端和提供者之间传输的数据(有效负载)

    WSDL act as an interface between sender and receiver. WSDL充当发送方和接收方之间的接口。
    SOAP message is request and response in xml format. SOAP消息是xml格式的请求和响应。

    comparing with java RMI 与java RMI比较

    WSDL is the interface class WSDL是接口类
    SOAP message is marshaled request and response message. SOAP消息是封送的请求和响应消息。

    We can consider a telephone call In that Number is wsdl and exchange of information is soap. 我们可以考虑拨打电话,该号码是wsdl,信息交换是肥皂。

    WSDL is description how to connect with communication server.SOAP is have communication messages. WSDL描述了如何与通信服务器连接.SOAP具有通信消息。

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

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