php+soap 入门

本文介绍了如何使用 PHP 的 SOAP 客户端来调用 Web 服务并获取天气预报数据,包括不带参数的方法调用和带参数的方法调用示例。此外,还展示了如何设置 SOAP 服务器及其实现简单的接口调用。
  1. 通过开放的webservice获取天气预报数据
  2. 代码
    <?php
    $c = new SoapClient( 'http://www.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl',
    array( 'trace' => true, 'exceptions' => true ) );//var_dump( $c->__getFunctions() );
    //var_dump( $c->__getTypes() );
    //不需要参数的情况
    $pr =$c->getRegionProvince();
    //var_dump( $pr->getRegionProvinceResult->string );
    //带有参数的情况
    $scs = $c->getSupportCityString( array( 'theRegionCode' => '福建' ) );
    var_dump( $scs->getSupportCityStringResult->string );
    var_dump($scs);
    //也可以这样做
    $we = $c->__call('getWeather', array( array( 'theCityCode' => 2210) ) );
    var_dump( $we );

    ?>
  3. soapserver和soapclient简单实现
  4. soapclient
    <?php
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    $ss = new SoapClient( null, array( 'uri' => 'http://zendstudio.net', 'location' => 'http://localhost/soaptest/soapserver.php' ) );
    $header = new SoapHeader( 'zendHeader', 'mmcYY', '12345678' );
    $ss->__setSoapHeaders( $header );
    echo $ss->im8( 'gently' );

    ?>
     
  5. soapserver 写道
    <?php
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    $ss = new SoapServer( null, array( 'uri' => 'http://zendstudio.net' ) );
    $ss->setClass( 't', '参数1', '参数2' );
    $ss->handle();
    //$request = file_get_contents( 'php://input' );
    //file_put_contents( 'request.txt', $request );
    class t{

    function __construct( $p1, $p2 ){

    }

    function im8( $g ){
    return 'OK----'. $g;
    }

    }

    ?>
     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值