天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

淺談PHP調用Webservice思路及源碼分享

方法一:直接調用

復制代碼 代碼如下:
<? 
/******************************************************************************/
/*  文件名 : soapclient.php
/*  說  明 : WebService接口客戶端例程
/******************************************************************************/
include('NuSoap.php'); 

// 創建一個soapclient對象,參數是server的WSDL  
$client = new soapclient('http://localhost/Webservices/Service.asmx?WSDL', 'wsdl'); 

// 參數轉為數組形式傳遞 
$aryPara = array('strUsername'=>'username', 'strPassword'=>MD5('password')); 

// 調用遠程函數 
$aryResult = $client->call('login',$aryPara); 

//echo $client->debug_str; 
/*
if (!$err=$client->getError()) {
  print_r($aryResult); 
} else { 
  print "ERROR: $err"; 
}
*/

$document=$client->document; 
echo <<<SoapDocument 
<?xml version="1.0" encoding="GB2312"?> 
 <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd"> 
   <SOAP-ENV:Body> 
   $document
   </SOAP-ENV:Body> 
 </SOAP-ENV:Envelope> 
SoapDocument; 

?> 

復制代碼 代碼如下:
<?
/******************************************************************************/
/*  文件名 : soapclient.php
/*  說  明 : WebService接口客戶端例程
/******************************************************************************/
include('NuSoap.php');

// 創建一個soapclient對象,參數是server的WSDL
$client = new soapclient('http://localhost/Webservices/Service.asmx?WSDL', 'wsdl');

// 參數轉為數組形式傳遞
$aryPara = array('strUsername'=>'username', 'strPassword'=>MD5('password'));

// 調用遠程函數
$aryResult = $client->call('login',$aryPara);

//echo $client->debug_str;
/*
if (!$err=$client->getError()) {
  print_r($aryResult);
} else {
  print "ERROR: $err";
}
*/

$document=$client->document;
echo <<<SoapDocument
<?xml version="1.0" encoding="GB2312"?>
 <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd">
   <SOAP-ENV:Body>
   $document
   </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>
SoapDocument;

?>

方法二:代理方式調用

復制代碼 代碼如下:
<? 
/******************************************************************************/
/*  文件名 : soapclient.php
/*  說  明 : WebService接口客戶端例程
/******************************************************************************/
require('NuSoap.php');  

//創建一個soapclient對象,參數是server的WSDL  
$client=new soapclient('http://localhost/Webservices/Service.asmx?WSDL', 'wsdl');  

//生成proxy類  
$proxy=$client->getProxy();  

//調用遠程函數  
$aryResult=$proxy->login('username',MD5('password')); 

//echo $client->debug_str; 
/*
if (!$err=$proxy->getError()) {
  print_r($aryResult); 
} else { 
  print "ERROR: $err"; 
}
*/

$document=$proxy->document; 
echo <<<SoapDocument 
<?xml version="1.0" encoding="GB2312"?> 
 <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd"> 
   <SOAP-ENV:Body> 
   $document
   </SOAP-ENV:Body> 
 </SOAP-ENV:Envelope> 
SoapDocument; 

?> 

復制代碼 代碼如下:
<?
/******************************************************************************/
/*  文件名 : soapclient.php
/*  說  明 : WebService接口客戶端例程
/******************************************************************************/
require('NuSoap.php');

//創建一個soapclient對象,參數是server的WSDL
$client=new soapclient('http://localhost/Webservices/Service.asmx?WSDL', 'wsdl');

//生成proxy類
$proxy=$client->getProxy();

//調用遠程函數
$aryResult=$proxy->login('username',MD5('password'));

//echo $client->debug_str;
/*
if (!$err=$proxy->getError()) {
  print_r($aryResult);
} else {
  print "ERROR: $err";
}
*/

$document=$proxy->document;
echo <<<SoapDocument
<?xml version="1.0" encoding="GB2312"?>
 <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd">
   <SOAP-ENV:Body>
   $document
   </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>
SoapDocument;
?>

  許多使用NuSoap 調用.NET WebService或J2EE  WebService的朋友可能都遇到過中文亂碼問題,下面介紹這一問題的出現的原因和相應的解決方法。
  NuSoap調用WebService出現亂碼的原因:
  通常我們進行WebService開發時都是用的UTF-8編碼,這時我們需要設置:
復制代碼 代碼如下:
$client->soap_defencoding = 'utf-8';
$client->soap_defencoding = 'utf-8';

  同時,需要讓xml以同樣的編碼方式傳遞:
復制代碼 代碼如下:
$client->xml_encoding = 'utf-8';
$client->xml_encoding = 'utf-8';

  至此應該是一切正常了才對,但是我們在輸出結果的時候,卻發現返回的是亂碼。
  NuSoap調用WebService出現亂碼的解決方法:
  實際上,開啟了調試功能的朋友,相信會發現$client->response返回的是正確的結果,為什么$result = $client->call($action, array('parameters' => $param)); 卻是亂碼呢?
  研究過NuSoap代碼后我們會發現,當xml_encoding設置為UTF-8時,NuSoap會檢測decode_utf8的設置,如果為true,會執行 php 里面的utf8_decode函數,而NuSoap默認為true,因此,我們需要設置:
復制代碼 代碼如下:
$client->soap_defencoding = 'utf-8'; 
$client->decode_utf8 = false; 
$client->xml_encoding = 'utf-8';
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false;
$client->xml_encoding = 'utf-8';

php技術淺談PHP調用Webservice思路及源碼分享,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 一本大道香蕉中文在线视频观看 | 国产精品久久久久久久久久免费 | jyzzjyzzz视频国产在线观看 | 亚洲熟妇无码乱子AV电影 | 寻找最美乡村教师颁奖晚会 | 伊人久久艹 | 亚洲国产精品热久久 | 亚州视频一区 | 精品国产免费人成视频 | 日韩精品特黄毛片免费看 | 日本理论片午午伦夜理片2021 | 乱爱性全过程免费视频 | 国产一区二区青青精品久久 | 一一本之道高清手机在线观看 | 中文字幕伊人香蕉在线 | 国产高清视频a在线大全 | 美女的隐私蜜桃传媒免费看 | 又硬又粗又大一区二区三区视频 | 神马老子影院午夜伦 | 免费在线视频成人 | 九九热综合 | 久久九九少妇免费看A片 | 亚洲国产成人精品久久久久 | 他揉捏她两乳不停呻吟口述 | 野花社区WWW韩国日本 | videossexotv极度另类 | BL低喘贯穿顶弄老师H | 亚洲看片无码免费视频 | 亚洲一二三产品区别在哪里 | 涩涩在线观看免费视频 | 色综合99久久久国产AV | 777久久人妻少妇嫩草AV | 99久久久精品免费观看国产 | 校花娇喘呻吟校长陈若雪视频 | 精品少妇高潮蜜臀涩涩AV | 506070老熟肥妇bbwxx视频 4虎最新网址 | 在线亚洲国产日韩欧洲专区 | 欧美性色xo影院69 | 99视频精品全部免费免费观 | 久久中文字幕无码A片不卡 久久中文字幕人妻熟AV女蜜柚M | 国产永久视频 |