Body的SoapServer set属性

时间:2014-08-17 09:32:06

标签: php xml soap

在PHP中使用SoapServer类我可以创建响应消息。

是否可以在响应中将属性设置为body标签?

PHP代码

ini_set( "soap.wsdl_cache_enabled", "0");
$server = new SoapServer('myWsdl.wsdl');
$server->addFunction("GetDetails");
$server->handle();

目前的结果:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
        <ns1:GetDetailsResponse/>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

预期结果:

<SOAP-ENV:Body Id="some_id">

1 个答案:

答案 0 :(得分:0)

当然,您可以尝试以下方式:

ini_set( "soap.wsdl_cache_enabled", "0");
$server = new SoapServer('myWsdl.wsdl');
$server->addFunction("GetDetails");

ob_start();
$server->handle();
$soap = ob_get_contents();
ob_end_clean();

$soap = str_replace("<SOAP-ENV:Body>", '<SOAP-ENV:Body Id="some_id">', $soap);

$length = strlen($soap);
header("Content-Length: ".$length);

echo $soap;

当然,如果str_replace()让您觉得有点脏,可以随时将$soap作为DOMDocument加载并在那里进行操作。