duanpang1987 2012-01-12 21:08
浏览 48
已采纳

捕获SOAP的错误?

How to catch an error from a SOAP?

How can I avoid the fatal error and convert it to my own error.. In this example it's a SERVER_BUSY

code

class Validate_vatno {
    private $client = null;

    private $options = array(
        'debug' => false
        );

    public function __construct(){
        $this->client = new SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl', array('trace' => true));
    }

    public function check($country, $vatno){
        $result = $this->client->checkVat(array(
            'countryCode' => $country,
            'vatNumber' => $vatno
            ));

        if(!empty($this->options['debug'])){
            echo '<pre>'.htmlentities($this->client->__getLastResponse()).'</pre>';
        }

        if($result->valid){
            list($denomination, $name) = explode(' ', $result->name, 2);

            return array(
                'denomination' => utf8_decode($denomination),
                'name' => ucwords(utf8_decode($name)),
                'address' => ucwords(utf8_decode($result->address)),
                );
        }
        else{
            return array();
        }
    }
}
$vatValidation = new Validate_vatno();

if($return = $vatValidation->check('DK', 33214944)){
    echo '<h1>valid one!</h1>';
    echo 'denomination: ' . $return['denomination']. '<br/>';
    echo 'name: ' . $return['name']. '<br/>';
    echo 'address: ' . $return['address']. '<br/>';
}
else{
    echo '<h1>Invalid VAT</h1>';
}

error

Fatal error: Uncaught SoapFault exception: [soapenv:Server] { 'SERVER_BUSY' } in /var/www/
  • 写回答

1条回答 默认 最新

  • dozxos6346 2012-01-12 21:11
    关注

    Review how to handle exceptions

    Throwing and Catching a Exception

    <?php
    function inverse($x) {
        if (!$x) {
            throw new Exception('Division by zero.');
        }
        else return 1/$x;
    }
    
    try {
        echo inverse(5) . "
    ";
        echo inverse(0) . "
    ";
    } catch (Exception $e) {
        echo 'Caught exception: ',  $e->getMessage(), "
    ";
    }
    
    // Continue execution
    echo 'Hello World';
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度