SOAP在非WSDL模式下的问题

时间:2015-01-02 16:58:41

标签: php soap wsdl

我正在制作一个简单的网络服务,用于我拥有的两个网站之间的通信。

由于它只是一个基本的应用程序,我在没有WSDL文件的情况下工作,因此在non-WSDL mode中,PHP手册会调用它。

这基本上就是客户端的样子:

$client = new SoapClient(null, array('location' => $location, 'uri' => '', 'trace' => TRUE));

$res = $client->__soapCall('myFunc', array($param));

在服务器端,我有一个名为myFunc的函数:

$soap = new SoapServer(null, array('uri' => ''));

$soap->addFunction('myFunc');

//Use the request to invoke the service
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $soap->handle();
}

当我实际尝试调用myFunc函数时,我得到并且错误:

Function 'ns1:myFunc' doesn't exist

由于某种原因,soap服务器正在将ns1:添加到函数名称前面!

使用$client->__getLastRequest(),我得到:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
    <ns1:getTopElement>
        <param0 xsi:type="xsd:string">rightcolBox</param0>
    </ns1:getTopElement>
</SOAP-ENV:Body>

我不是SOAP专家,但在我看来,客户端在发出请求时会导致错误 - 或者服务器是否误解了它?

如何解决此问题?

1 个答案:

答案 0 :(得分:-1)

我遇到了同样的问题。当我设置SoapClient选项&#39;如果不为空,问题就解决了。

$client = new SoapClient(null, array('location' => $location, 'uri' => 'foo', 'trace' => TRUE));

是的,它可以是任何字符串,甚至&#34; foo&#34;如本例所示。