php+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;
    }

    }

    ?>
     

你可能感兴趣的:(C++,c,PHP,webservice,SOAP)