好的,我正在学习 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 请求来确定使用哪种方法和发送哪种响应仅
吗?
为什么示例在 Envelope 中使用命名空间 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
?它不能只发送带有所需标签的简单 XML、解析它并发送答案吗?
最佳答案
很多问题,我猜你问是出于好奇,所以我试着“只是”自上而下地回答它们,希望有一些提示可以帮助你进一步定位:
Can't the server determine which method to use and which response to send only by parsing the SOAP request?
确实如此。从客户端的角度来看,WSDL 仅用于告诉您服务是什么(服务的描述)以及 - 在 PHP SoapClient 的情况下 - 帮助您访问服务(采用 仅有保留意见,在 WSDL 模式下使用 SoapClient 通常是推荐的使用方式。
Why do we need the WSDL file?
它包含机器可读格式的服务描述。如果您需要了解该服务,则需要它。如果您了解该服务并且可以将您需要的每个请求一起键入,则不需要它(如果该服务处理多个操作和复杂类型,则不推荐)。
Why do we need
portType
[... ?]
portType, which is a set of abstract operations. Each operation refers to an input message and output messages.
它是定义服务的六大要素之一。有关端口类型的更多详细信息,请参见: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?
那是“只是”发送 XML。这些元素遵循 XML 命名空间的命名法,仅此而已。因此,逐字回答这个问题:不,它不能只发送简单的(非命名空间的)XML,因为它需要知道其命名空间中的标签以识别它们。
这样做是为了将 SOAP 信封与消息正文中的其他信息分开,这些信息也是 XML 编码的。想象一下服务消息也可以处理信封、消息或标题。很可能会出现名称冲突,因此命名空间对于区分 SOAP 消息的信封和作为从服务发送或检索的对象的信封很重要。
关于php - 为什么我们需要带有 SOAP 的 WSDL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32459266/