为什么我们需要带有 SOAP 的 WSDL?

Why do we need WSDL with SOAP?

好的,我正在学习 SOAP。 Here 是一个 SOAP 请求和一个 SOAP 响应,以及 WSDL。

为什么我们需要 WSDL 文件?为什么我们需要portType,喜欢

  <wsdl:portType name="GetEndorsingBoarderPortType">
      <wsdl:operation name="GetEndorsingBoarder">
         <wsdl:input message="es:GetEndorsingBoarderRequest"/>
         <wsdl:output message="es:GetEndorsingBoarderResponse"/>
         <wsdl:fault message="es:GetEndorsingBoarderFault"/>
      </wsdl:operation>
   </wsdl:portType>

服务器不能通过解析 SOAP 请求来确定使用哪种方法和发送哪种响应only

为什么示例在信封中使用命名空间 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"?它不能只发送一个简单的 XML 和所需的标签,解析它并发送一个答案吗?

很多问题,我猜你问是出于好奇,所以我试着回答它们 "just" top-down 希望有一些提示可以帮助你进一步定位:

Can't the server determine which method to use and which response to send only by parsing the SOAP request?

确实如此。客户端角度的 WSDL 仅用于告诉您服务是什么(服务的描述)以及 - 在 PHP SoapClient 的情况下 - 帮助您访问服务(对 only 持保留态度,在 WSDL 模式下使用 SoapClient 通常是推荐的使用方式)。


Why do we need the WSDL file?

它包含 machine-readable 格式的服务描述。如果您需要了解该服务,则需要它。如果您了解该服务并且可以将您需要的每个请求一起键入,则不需要它(如果该服务处理多个操作和复杂类型,则不推荐)。


Why do we need portType [... ?]

引用自the specification

portType, which is a set of abstract operations. Each operation refers to an input message and output messages.

它是定义服务的六大要素之一。有关 port-types 的更多详细信息,请参见此处:http://www.w3.org/TR/wsdl#_porttypes - 根据服务的不同,这些可能会有所不同,并且有些服务没有 PortTypes 以及 IIRC(可能仅在早期的 SOAP 版本中,不能从顶部确定我的头)。


And why does the example use the namespace xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" in the Envelope? Can't it just send a simple XML with the needed tags, parse it and send an answer?

即"just"发送XML。这些元素遵循 XML 命名空间的命名法,仅此而已。所以逐字回答这个问题:不,它不能只发送简单的 (non-namespaced) XML 因为它需要知道它们命名空间中的标签来识别它们。

这样做是为了将 SOAP 信封与消息 body 中的其他信息分开,后者也是 XML 编码的。想象一下服务消息也可以处理信封或消息或 header。很可能会出现名称冲突,因此名称空间对于区分 SOAP 消息的信封和作为从服务发送或检索的 object 的信封很重要。