php
  • soap
  • wsdl
  • soap-client
  • soapfault
  • 2016-02-12 88 views 0 likes 
    0

    我正在调用第三方Web服务以获取用户提供的凭证详细信息。以下是我的Soap客户端请求。如何在PHP中处理SoapClient错误

    $client = new \SoapClient($url, array("exception" => 0));   
    $auth = ' 
    <wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
    <wsse:UsernameToken> 
    <wsse:Username>' . $userName . '</wsse:Username> 
    <wsse:Password>' . $password . '</wsse:Password> 
    </wsse:UsernameToken> 
    </wsse:Security>'; 
    $authvalues = new \SoapVar($auth, XSD_ANYXML); 
    $header1 = new \SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", $authvalues, true); 
    $header2 = new \SoapHeader("http://xmlns.myweb.com/FulfillProductRequest/V1", "v1");  
    $header3 = new \SoapHeader("http://xmlns.myweb.com/ParameterType/V2", "v2");  
    $header4 = new \SoapHeader("http://xmlns.myweb.com/RequestHeader/V3", "v3"); 
    
    $header = array();  
    $header[] = $header1;  
    $header[] = $header2;  
    $header[] = $header3;  
    $header[] = $header4;     
    $client->__setSoapHeaders($header);  
    $res = $client->FulfillProduct($FulfillProductRequest);  
    

    当我打电话的WSDL,如果我得到成功响应,那么就没有问题。

    但是,如果在soapFault中出现任何错误,那么我的代码会显示致命错误。

    任何人都有任何想法如何处理SoapFault PLZ份额。

    非常感谢。

    回答

    0

    您可以尝试将您的$res = $client→FulfillProduct($FulfillProductRequest);换成try { } catch() {}

    例如:

    try { 
        $res = $client→FulfillProduct($FulfillProductRequest); 
    } catch(Exception $e) { 
        // An error has occured. 
        // All information about the error has been stored in variable $e 
        print_r($e); 
    } 
    

    要知道,你可以设置SoapClient从不抛出异常带的设置,所以考虑,第一。

    +0

    我正在使用try catch块。但无法处理致命的错误。致命错误:Unocaught SoapFault异常:[env:Server] XXXXXXXXXXXXX XXX XXXXX – MANOJ

    +0

    在您的SoapClient参数中,您已设置'exceptions => 0'。删除它,因为它阻止了SoapClient抛出异常。 –

    +0

    删除后也不起作用。我得到了同样的错误(致命错误) – MANOJ

    相关问题