我不确定这是 php 错误(错误的实现)还是我的错误(对 SOAP 协议/SoapServer 的理解不佳,因为这是我第一次使用 SoapServer)
我注意到如果有两个或多个相同的操作wsdl:part
(即使wsdl:message
, operation 和 soapAction 不同), TheSoapServer
总是会调用第一个函数。在这个例子中,我有两个函数multiply2
,并且multiply4
都有num
(int) 作为输入参数。今天早些时候,如果我更改部件名称 (service1.wsdl),则功能映射正确。
虽然,我不介意使用不同的名称,但在我看来它就像一个错误。我错过了什么还是应该打开一个错误?
这是我创建的简单示例:
非常简单的php类
<?php
class Multi
{
function multiply2($num) { return ($num * 2 ); }
function multiply4($num){ return ($num * 4 ); }
}
?>
并且稍微改变了 SoapServer (增加了日志记录 -改编自这篇文章)但是当我使用普通的 SoapServer 时也会出现问题:
$server = new overloadedSoapServer("service.wsdl", array('soap_version' => SOAP_1_2,'encoding' => SOAP_ENCODED));
$server->setClass("multi");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$server->handle();
}
这是客户端代码:
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient('service.wsdl');
$client1 = new SoapClient('service1.wsdl');
echo "<pre>\nFrom service.wsdl:";
echo "\n".$client->multiply2(10);
echo "\n".$client->multiply4(10);
echo "</pre>";
echo "<pre>\nFrom service1.wsdl:";
echo "\n".$client1->multiply2(10);
echo "\n".$client1->multiply4(10);
echo "</pre>";
service.wsdl
并且service1.wsdl
基本上是相同的文件,但有两个例外:
- 它们的端点不同(
service.wsdl
指向http://tests.simsimy.info/web/service.php
和service1.php
指向http://tests.simsimy.info/web/service1.php
每个端点使用适当的 wsdl 来加载SoapServer
) - in
service.wsdl
multiply2Request
和multiply4Request
具有作为部件名称 -num
,而 inservice1.wsdl
名称不同 (num2
andnum4
)
这是 service.wsdl 的完整 wsdl
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://tests.simsimy.info/web/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="service"
targetNamespace="http://tests.simsimy.info/web/">
<wsdl:message name="multiply2Request">
<wsdl:part name="num" type="xsd:int"></wsdl:part>
</wsdl:message>
<wsdl:message name="multiply2Response">
<wsdl:part name="res" type="xsd:int"></wsdl:part>
</wsdl:message>
<wsdl:message name="multiply4Request">
<wsdl:part name="num" type="xsd:int"></wsdl:part>
</wsdl:message>
<wsdl:message name="multiply4Response">
<wsdl:part name="res" type="xsd:int"></wsdl:part>
</wsdl:message>
<wsdl:portType name="dd">
<wsdl:operation name="multiply2">
<wsdl:input message="tns:multiply2Request"></wsdl:input>
<wsdl:output message="tns:multiply2Response"></wsdl:output>
</wsdl:operation>
<wsdl:operation name="multiply4">
<wsdl:input message="tns:multiply4Request"></wsdl:input>
<wsdl:output message="tns:multiply4Response"></wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="serviceSOAP" type="tns:dd">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="multiply2">
<soap:operation soapAction="http://tests.simsimy.info/web/multiply2" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="multiply4">
<soap:operation soapAction="http://tests.simsimy.info/web/multiply4" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="multiply_service">
<wsdl:port binding="tns:serviceSOAP" name="serviceSOAP">
<soap:address location="http://tests.simsimy.info/web/service.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
中的更改部分service1.wsdl
:
<wsdl:message name="multiply2Request">
<wsdl:part name="num2" type="xsd:int"></wsdl:part>
</wsdl:message>
<wsdl:message name="multiply2Response">
<wsdl:part name="res" type="xsd:int"></wsdl:part>
</wsdl:message>
<wsdl:message name="multiply4Request">
<wsdl:part name="num4" type="xsd:int"></wsdl:part>
</wsdl:message>
<wsdl:message name="multiply4Response">
<wsdl:part name="res" type="xsd:int"></wsdl:part>
</wsdl:message>
当我运行客户端代码时,我得到以下输出:
From service.wsdl:
20
20
From service1.wsdl:
20
40