尝试使用 PHP 访问我自己的 PHP Soap 服务时遇到问题。我将 Zend_Soap 用于客户端和服务器。
基本上,我从客户端得到的结果是空的。但是,如果我查看最后一个响应,它包含预期的正确 XML。因此客户端无法将 xml 转换为 php 对象(在我的测试用例中,是一个简单的 int)以供使用。
我的 wsdl 看起来像这样
<definitions name="SOAP_Model_soaphandler" targetNamespace="http://website.com/appldev/applications/public/SOAP/index/soap">
<types>
<xsd:schema targetNamespace="http://website.com/appldev/applications/public/SOAP/index/soap"/>
</types>
<portType name="SOAP_Model_soaphandlerPort">
<operation name="test">
<documentation>Returns list of all products in database</documentation>
<input message="tns:testIn"/>
<output message="tns:testOut"/>
</operation>
<operation name="test2">
<documentation>Adds new product to database</documentation>
<input message="tns:test2In"/>
<output message="tns:test2Out"/>
</operation>
</portType>
<binding name="SOAP_Model_soaphandlerBinding" type="tns:SOAP_Model_soaphandlerPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="test">
<soap:operation soapAction="http://website.com/appldev/applications/public/SOAP/index/soap#test"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://website.com/appldev/applications/public/SOAP/index/soap"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://website.com/appldev/applications/public/SOAP/index/soap"/>
</output>
</operation>
<operation name="test2">
<soap:operation soapAction="http://website.com/appldev/applications/public/SOAP/index/soap#test2"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://website.com/appldev/applications/public/SOAP/index/soap"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://website.com/appldev/applications/public/SOAP/index/soap"/>
</output>
</operation>
</binding>
<service name="SOAP_Model_soaphandlerService">
<port name="SOAP_Model_soaphandlerPort" binding="tns:SOAP_Model_soaphandlerBinding">
<soap:address location="http://website.com/appldev/applications/public/SOAP/index/soap"/>
</port>
</service>
<message name="testIn"/>
<message name="testOut">
<part name="return" type="xsd:int"/>
</message>
<message name="test2In">
<part name="id" type="xsd:int"/>
</message>
<message name="test2Out">
<part name="return" type="soap-enc:Array"/>
</message>
</definitions>
我的回复看起来像这样
<env:envelope xmlns:enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://website.com/appldev/applications/public/SOAP/index/soap" xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:body xmlns:rpc="http://www.w3.org/2003/05/soap-rpc">
<ns1:testresponse env:encodingstyle="http://www.w3.org/2003/05/soap-encoding">
<rpc:result>return</rpc:result>
<return xsi:type="xsd:int">7</return>
</ns1:testresponse>
</env:body>
</env:envelope>
但
$result=$client->test();
var_dump($result);
输出 NULL。
有任何想法吗?看起来它应该对我有用,但我不是肥皂客户端如何工作的专家。也许命名空间有问题或其他什么?我真的不知道。似乎它应该可以正常工作。作为参考,我按照本指南启动并运行:
http://www.ibm.com/developerworks/webservices/library/x-zsoap/index.html
我想我总是可以手动从 xml 获取响应,但我希望弄清楚为什么客户端不为我这样做。