php webservice实战

做这个测试之前,要确认你的php配置文件中已经将soap扩展打开,即extension=php_soap.dll;

//server端 serverSoap.php

<?php

define(‘WBIN‘, TRUE);


$soap = new SoapServer(null,array(‘uri‘=>"http://192.168.1.11/"));//This uri is your SERVER ip.
$soap->addFunction(‘addData_func‘);  //Register the function
$soap->addFunction(SOAP_FUNCTIONS_ALL);
$soap->handle();


function addData_func($data  = array()){
    return json_encode($data);

}

//client端 clientSoap.php

<?php
define(‘WBIN‘, TRUE);
include ‘config.inc.php‘;
include ‘DBmysql.class.php‘;
include ‘common.func.php‘;
include ‘Curl.class.php‘;
error_reporting(E_ALL);
header("Content-type:text/html;charset=utf-8");


function getLoanInfo()
{
$_db = new DBmysql();

$sql = "SELECT
cld.account_number,cld.accntnm,cld.amt,cld.loan_num,cld.loan_type,cld.loan_time,cld.remark,cld.card,
crd.repay_num,crd.first_repay,crd.repay_date
FROM
crm_loan_dk as cld,
crm_repay_dk as crd

where cld.account_number = crd.account_number 

and cld.status = 2 ";
$rs = $_db->executeQuery($sql);
//echo json_encode($rs);


//webservice post array
try {
   $client = new SoapClient(null,
       array(‘location‘ =>"http://192.168.1.11/text/webs/serverSoap.php",‘uri‘ => "http://192.168.1.11/")
   );
   echo $client->addData_func($rs);


} catch (SoapFault $fault){
   echo "Error: ",$fault->faultcode,", string: ",$fault->faultstring;
}
}


$action = strtolower(getParam(‘a‘));
switch ($action)
{
case ‘loaninfo‘:         //放款用户基本信息
getLoanInfo();
break;
}

客户端调用服务器端函数

php webservice实战,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。