【问题标题】:php soap server return plain responsephp soap 服务器返回普通响应
【发布时间】:2013-08-29 10:23:16
【问题描述】:

实际上,我创建了一个 Soap 代理,在其中我获取客户端请求,我需要将请求进一步发布到另一个 SOAP 服务器(使用 c_url)。

成功获得响应(作为带有<SOAP-ENV 和所有其他的xml)。

问题在于,在我的 SOAP 代理中,我想准确返回响应,如果我的服务器返回 xml,那么 SOAP 服务器实际上会返回 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>

问题是:我怎样才能让soap服务器准确地返回我想要的响应而不用soap信封和其他东西包装起来?

谢谢。

更新:

我的肥皂服务器:

$server = new SoapServer($myOwnWsdlPath);
$this->load->library('SoapProxy');
$server->setClass('SoapProxy', $params );
$server->handle();

我的带有 c_url 的肥皂 Porxy:

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-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>

【问题讨论】:

  • 那么是什么阻止你这样做呢?让我感到困惑的是:这实际上与 SOAP 相关还是只是传递 HTTP 请求(代理它)?
  • 客户端向我的 SOAP SERVER 发出一个肥皂请求,我向另一个 SOAP SERVER 发出同样的请求,这个 XML 响应应该被发送回我的客户端。
  • 是的,我的问题是,是什么阻止您这样做? Per-Se 我不明白为什么这是不可能的,那么你的代码在哪里?还是你没有代码?
  • 我已经更新了问题

标签: php curl proxy soapserver


【解决方案1】:

我发现的解决方法是扩展 SoapServer 的“句柄”功能

丢弃 SoapServer 的输出(使用 ob_end_clean)并用我的数据替换它

class MySoapServer extends SoapServer
{
    public function handle($soap_request = null)
    {
        parent::handle();
        ob_end_clean();
        ob_start();
        echo $_SESSION['data'];

    }
}

【讨论】:

  • 令人惊讶的是,许多与 PHP SOAP 相关的问题都没有得到解答,但得到答案的问题实际上来自他们的 OP。
  • 在 PHP 中使用 SOAP 是一场噩梦。相信我。
猜你喜欢
  • 2014-01-13
  • 2021-04-06
  • 2019-04-28
  • 2014-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多