我正在重写 SoapClient 中的 doRequest 函数,以便解析/解码响应。请求被很好地发送,响应的内容很好。我遇到的问题是第二个函数(__myDoRequest)返回一个字符串,而不是一个对象。
我怀疑由于 myDoRequest 绕过了 __call,所以 __call 必须以某种方式格式化响应。我不能(据我所知)覆盖 __call,因为它需要函数名称和参数,在 myDoRequest 的情况下我不知道(我只是重新生成标题,并将 xml 复制到正文中)。有没有不涉及解析 xml 文档以获取函数/参数的解决方案?
注意事项:
$this->parse_response($response)
: 返回一个字符串
简而言之:
$this->soapclient->__doRequest(...);
: 返回字符串
$this->soapclient->name_of_search($request)
:返回对象(stdClass)
我想$this->soapclient->name_of_search($request)
返回一个对象,而不是一个字符串。
__称呼
public function __call($function_name, $arguments)
{
$this->__setSoapHeaders($this->generateWSSecurityHeader());
return parent::__call($function_name, $arguments);
}
__doRequest
public function __doRequest($request, $location, $action, $version, $one_way = 0)
{
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
return $this->parse_response($response);
}
__myDoRequest
function __myDoRequest($request, $location, $action, $version, $one_way = 0)
{
//Set up the new headers
$xml = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="..." xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<SOAP-ENV:Header>';
$xml .= $this->generateWSSecurityHeader("xml");
$xml .= "</SOAP-ENV:Header><SOAP-ENV:Body>";
$xml .= $request;
$xml .= "</SOAP-ENV:Body></SOAP-ENV:Envelope>";
$response = parent::__doRequest($xml, $location, $action, $version, $one_way);
if((isset($this->__soap_fault)) && ($this->__soap_fault != null))
{
$exception = $this->__soap_fault;
if($exception != null)
{
throw $exception;
}
}
return $this->parse_response($response);
}
他们是如何被调用的:
<snip>
if($raw_xml)
{
$response = $this->soapclient->__doRequest($raw_xml, '...', "", 1, 0);
}
else
{
$response = $this->soapclient->name_of_search($request);
}
<snip>