PHP之soap调用webservice实例

header ( "content-type:text/html;charset=utf-8" );
$param = array ('参数名' => '参数的值');//多个参数添加数组元素即可
$client = new SoapClient ( "http://www.xuejiehome.com/文件名.asmx?wsdl",array("connection_timeout" => 10 )  );
try {
     $p = $client->__soapCall ( '调用的方法名', array ('parameters' => $param ) );
     echo $p->Result;//获取得到的对象的属性值Result
} catch ( Exception $e ) {
     echo $e->getMessage ();
}

封装成方法如下:

//获取webservice内容
function getWebService($url, $method, $param, $timeOut=10) {
    ini_set ( 'default_socket_timeout', $timeOut );
    $client = new SoapClient ( $url, array ("connection_timeout" => $timeOut ) );
    try {
        $result = $client->__soapCall ( $method, array ('parameters' => $param ) );
        return $result;
    } catch ( Exception $e ) {
        //echo $e->getMessage();
        return - 1; //错误
    }
}

可根据自己的具体情况扩展。

by 雪洁 2011-12-07 14:21:45 7627 views

1 Comments

bPTsikKVuSLZYWdLwP 2013-03-27 02:35:09
VdqJOi Major thankies for the article post.Thanks Again. Great.
我来说几句

相关文章