我有一个很好用的简单肥皂服务器并返回POST请求的答案:
<?php
class result extends stdClass
{
public $ResultCode = '';
public $ResultDesc = '';
}
class answer
{
function lgi($a) {
$data = new result();
$data->ResultCode = '0';
$data->ResultDesc = 'Hi';
return $data;
}
}
$options = array(
'uri' => 'http://loooloo.com/LGI',
'location' => 'http://schemas.xmlsoap.org/soap/envelope/',
);
$soap = new SoapServer(null, $options);
$soap->setclass("answer");
$soap->handle();
?>
服务器发回:
<SOAP-ENV:Body>
<ns1:LGIResponse>
<return
xsi:type="SOAP-ENC:Struct">
<ResultCode xsi:type="xsd:string">
0
</ResultCode>
<ResultDesc xsi:type="xsd:string">
Hi
</ResultDesc>
</return>
</ns1:LGIResponse>
</SOAP-ENV:Body>
虽然我真正需要的是:
<SOAP-ENV:Body>
<LGOResponse>
<Result>
<ResultCode>0</ResultCode>
<ResultDesc>Hi</ResultDesc>
</Result>
</LGOResponse>
我看到了使用SoapVar和str_replace的客户端的示例,但它对我没用。还有其他想法吗?
感谢
答案 0 :(得分:0)
终于奏效了......
我用结果标记替换了返回标记并删除了类型:
<?php
class result extends stdClass
{
public $ResultCode = '';
public $ResultDesc = '';
}
class answer
{
function lgi($a) {
$data = new result();
$data->ResultCode = '0';
$data->ResultDesc = 'Hi';
return $data;
}
}
$options = array(
'uri' => 'http://loooloo.com/LGI',
'location' => 'http://schemas.xmlsoap.org/soap/envelope/',
);
$soap = new SoapServer(null, $options);
$soap->setclass("answer");
ob_start();
$soap->handle();
$soap1 = ob_get_contents();
ob_end_clean();
$soap1 = str_replace("<return xsi:type=\"SOAP-ENC:Struct\">", '<Result>', $soap1);
$soap1 = str_replace("xsi:type=\"xsd:int\"", '', $soap1);
$soap1 = str_replace("xsi:type=\"xsd:string\"", '', $soap1);
$soap1 = str_replace("</return>", '</Result>', $soap1);
echo $soap1;