Java SOAP消息和WSDL之间的区别?

Java SOAP消息和WSDL之间的区别?,java,web-services,soap,wsdl,Java,Web Services,Soap,Wsdl,我对SOAP消息和WSDL如何结合感到困惑?我已经开始研究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-e

我对SOAP消息和WSDL如何结合感到困惑?我已经开始研究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>
POST/InStock HTTP/1.1
主持人:www.example.org
内容类型:应用程序/soap+xml;字符集=utf-8
内容长度:nnn
国际商用机器公司
所有SOAP消息都是WSDL的吗?SOAP是接受自己的“SOAP消息”还是“WSDL”的协议?如果它们不同,那么什么时候应该使用SOAP消息,什么时候应该使用WSDL消息

对此进行一些澄清将非常棒。

WSDL(Web服务定义语言)是描述Web服务的元数据文件

操作名称、参数等


soap消息是实际有效载荷

soap消息是用于传输数据的XML文档。WSDL是一个XML文档,它描述了如何连接和请求web服务

基本上,SOAP消息是您传输的数据,WSDL告诉您可以做什么以及如何进行调用

在谷歌上快速搜索将产生许多额外的阅读来源(以前的图书链接现在已经失效,为了解决这个问题,任何新的推荐都会放在评论中)

请注意您的具体问题:

所有的SOAP消息都是WSDL吗?不,它们根本不是一回事

SOAP是一种接受自己的“SOAP消息”或“WSDL”的协议吗?不需要读取,因为这还远远不够


如果它们不同,那么什么时候应该使用SOAP消息,什么时候应该使用WSDL?SOAP是您应用于要传输的消息/数据的结构。wsdl仅用于确定如何首先调用服务。当您第一次添加代码来调用特定的Web服务时,这通常是一次性的

每个请求发送一个SOAP文档。假设我们是一家书店,我们查询了一个远程服务器,以了解特定书籍的当前价格。假设我们需要将书的标题、页数和ISBN号传递给服务器

每当我们想知道价格时,我们都会发送一条独特的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: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> 
<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>

978-0451524935
1984
328
我们希望得到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>

8.99
美元
然后,WSDL描述了当服务器接收到该消息时如何处理该消息。在我们的例子中,它描述了标题、NumPages和ISBN的类型,我们是否应该期望从GetBookPrice消息中得到响应,以及响应应该是什么样子

类型如下所示

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

但是WSDL还包含更多信息,关于哪些函数链接在一起进行操作,哪些操作在服务中可用,以及您可以访问服务/操作的网络位置


<>也见

我们可以考虑电话号码,号码是WSDL,信息交换是SOAP。< /P>
WSDL描述如何与通信服务器连接。SOAP具有通信消息。

简单地说,如果您有计算器的web服务。WSDL告诉您可以实现或向客户机公开的功能。例如:添加、删除、减去等。其中,在使用SOAP时,您实际上执行了doDelete()、doSubtract()和doAdd()等操作。所以SOAP和WSDL是苹果和桔子。我们不应该比较它们。它们都有各自不同的功能

肥皂: 它是一种基于XML的开放标准通信协议,用于将信息从用户交换到web服务,或从用户交换到web服务。 soap只是以某种方式组织数据的文档。 对于每个请求和响应,可能存在单独的soap

WSDL: 在soap中,数据是以某种方式组织的,这种组织是在WSDL中指定的,这里还指定了必须使用的数据类型。
对于请求和响应,将出现单个WSDL

我们需要先定义什么是web服务,然后才能说明SOAP和WSDL之间的区别,其中SOAP和WSDL是web服务的组件

大多数应用程序的开发都是为了与用户交互,用户通过界面输入或搜索数据,然后应用程序响应用户的输入

除了Web服务应用程序只在机器之间或应用程序之间通信之外,Web服务做的事情或多或少是相同的。通常没有直接的用户交互

Web服务基本上是用于在应用程序之间交换数据的开放协议的集合。开放协议的使用使Web服务能够独立于平台。用不同编程语言编写并在不同平台上运行的软件可以使用Web服务在计算机网络(如Internet)上交换数据。换句话说,Windows应用程序可以与PHP、Java和Perl应用程序以及许多其他应用程序进行通信,这在正常情况下是不可能的

Web服务是如何工作的

因为不同的应用程序是用不同的编程语言编写的,所以它们通常无法相互通信。Web服务通过使用开放协议和标准(主要是XML、SOAP和WSDL)的组合来实现这种通信。Web服务使用XML标记数据,使用SOAP传输消息,最后使用WSDL描述服务的可用性。让我们来看看Web服务应用程序的这三个主要组件。 简单对象访问协议(SOAP) 简单对象访问协议(Simple Object Access Protocol,SOAP)是一种用于在应用程序之间发送和接收消息的协议,而不会遇到互操作性问题
<?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>