duanmu0834 2012-07-26 23:21
浏览 56
已采纳

如何在php Soap Client请求期间处理多个SOAP错误?

I am interested in making a soap call via php’s soapClient to a web service to get the water level from a monitoring station. I want to handle two soapfaults that have occured during the execution. The first fault is as follows :

SoapFault exception: [soapenv:Server.userException] java.rmi.RemoteException: We are sorry, but no data is available from this station at this time in C:\xampp\htdocs\NOAA\LogWriter.php:214 Stack trace: #0 C:\xampp\htdocs\NOAA\LogWriter.php(214): SoapClient->__soapCall('getWaterLevelRa...', Array, Array) #1 C:\xampp\htdocs\NOAA\LogWriter.php(188): getLevel('8531680', '20120726 15:19') #2 {main}

This error is expected to occur several times during the script if the data for a certain time is not available. I need to catch this fault in order to tell the script to try again with a new time. I used a catch block to do so.

I also need to catch a second fault that occurs if the webservice is not loading the wsdl file or the server is timedout. To test for this have gave my script a faultly location to generate the same error I had received previously and it is as follows:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://opendap.co-ops.nos.noaa.gov/axis/services/WaterLevelRawOneMin?wsdl' : Extra content at the end of the document in C:\xampp\htdocs\NOAA\LogWriter.php:210 Stack trace: #0 C:\xampp\htdocs\NOAA\LogWriter.php(210): SoapClient->SoapClient('http://opendap....', Array) #1 C:\xampp\htdocs\NOAA\LogWriter.php(171): getLevel('8531680', '20120726 12:35') #2 {main} thrown in C:\xampp\htdocs\NOAA\LogWriter.php on line 210  

The second error remains uncaught and terminates my script. However I need to catch it and display a message.

I have posted my php function that makes the soap call below.

Could anyone give me any ideas on how to do this?

function getLevel($id, $date) {

    $client = new SoapClient("http://opendap.co-ops.nos.noaa.gov/axis/services/WaterLevelRawOneMin?wsdl", array('trace' => false));

    $Parameters = array("stationId" => $id, "beginDate" => $date, "endDate" => $date, "datum" => "MLLW",
                        "unit"      => 1, "timeZone" => 1);

    try {
        return $client->__soapCall(
            "getWaterLevelRawOneMin", array('Parameters' => $Parameters),
            array('location' => "http://opendap.co-ops.nos.noaa.gov/axis/services/WaterLevelRawOneMin")
        );
    } catch (SoapFault $e) {
        if (
            $e->faultcode == "soapenv:Server.userException"
            and $e->faultstring == "java.rmi.RemoteException: We are sorry, but no data is available from this station at this time"
        ) {
            return "FAULT";
        } else {
            echo "Could not connect to the server";
        }
    } // end of catch blocK
}// end of function
  • 写回答

1条回答 默认 最新

  • douwen7331 2012-07-27 00:05
    关注

    Exception regarding broken WSDL can occur only when you call SoapClient::constructor so

    try {
        $client= new SoapClient($wsdlUrl ,array('trace'=>false));
    }catch(Exception $e) {
        // your loging regarding this case 
    }
    

    SoapFault exception can occur when you make a webservice all so:

    try {
        $client= new SoapClient($wsdlUrl ,array('trace'=>false));
        try {
           return $client->_call('....');
        } catch (SoapFault $sp) {
            //your logic rearding soap fault 
        }
    }catch(Exception $e) {
        // your loging regarding this case 
    }
    return false;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP