覆盖SoapClient doRequest返回一个字符串,而不是一个对象

时间:2013-10-31 07:08:46

标签: php soap soap-client

我正在覆盖SoapClient中的doRequest函数,以便解析/解码响应。请求被发送正常,响应的内容很好。我得到的问题是第二个函数(__myDoRequest)返回一个字符串,而不是一个对象。

我怀疑myDoRequest会绕过__call,然后__call必须以某种方式格式化响应。我不能(据我所知)覆盖__call,因为它期望函数名称和参数,在myDoRequest的情况下我不知道(我只是重新生成标题,并将xml复制到正文中)。是否有任何解决方案涉及解析xml文档以获取函数/参数?

注意事项:

$this->parse_response($response):返回一个字符串

简而言之:

$this->soapclient->__doRequest(...);:返回字符串

$this->soapclient->name_of_search($request):返回object(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>

0 个答案:

没有答案
相关问题