实际上我创建了一个Soap Proxy,我在其中获得了客户端请求,我需要将请求进一步发布到另一个SOAP服务器(使用c_url)。
成功获得响应(作为xml,<SOAP-ENV
和所有其他人。)
问题是在我的SOAP PROXY中我想要准确地返回响应,如果我的服务器返回xml,SOAP Server实际上返回XML文件包装
<SOAP-ENV:Envelope ...>
<SOAP-ENV:Body>
<ns1:loginResponse>
my xml that already contains <soap:Envelope, <soap:Body> and <namesp1:loginResponse>
</ns1:loginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
问题是:如何让肥皂服务器准确地返回我想要的响应而不用肥皂信封和其他信封?
感谢。
更新:
我的肥皂服务器:
$server = new SoapServer($myOwnWsdlPath);
$this->load->library('SoapProxy');
$server->setClass('SoapProxy', $params );
$server->handle();
我的肥皂Porxy与c_url:
public function __call($actionName, $inputArgs)
{
//some logic
$target = ...
$url = ..
$soapBody =..
$headers = ..
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $soapBody); // the SOAP request
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch); //soap xml response
curl_close($ch);
file_put_contents('/tmp/SoapCurl.txt', var_export($response, true));
return $response;
}
来自/tmp/SoapCurl.txt的回复是正确的:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope ...>
<soap:Body>
<namesp1:loginResponse>
<session_id xsi:type="xsd:string">data</session_id>
</namesp1:loginResponse>
</soap:Body>
</soap:Envelope>
我的soap服务器响应错误:
<SOAP-ENV:Envelope ...>
<SOAP-ENV:Body>
<ns1:loginResponse>
<soap:Envelope ...>
<soap:Body>
<namesp1:loginResponse>
<session_id xsi:type="xsd:string">correct data</session_id>
</namesp1:loginResponse>
</soap:Body>
</soap:Envelope>
</ns1:loginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
答案 0 :(得分:2)
我发现的修复是扩展SoapServer的'handle'功能
丢弃SoapServer的输出(使用ob_end_clean)并将其替换为我的数据
class MySoapServer extends SoapServer
{
public function handle($soap_request = null)
{
parent::handle();
ob_end_clean();
ob_start();
echo $_SESSION['data'];
}
}