非 WSDL 模式下的 SOAP 问题


Issues with SOAP in non-WSDL mode

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

由于它只是一个基本的应用程序,我一直在没有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 专家,但在我看来,客户端在发出请求时导致了错误 - 还是服务器误解了它?

如何解决此问题?

我遇到了同样的问题。当我将 SoapClient 选项的 uri 设置为不空时,问题就解决了。

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

的,它可以是任何字符串,甚至是本例中的"foo"。