激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - PHP教程 - 淺談PHP調用Webservice思路及源碼分享

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

2020-07-01 14:24PHP教程網 PHP教程

NuSoap是PHP環境下的WebService編程工具,用于創建或調用WebService。它是一個開源軟件,是完全采用PHP語言編寫的、通過HTTP收發SOAP消息的一系列PHP類。NuSOAP的一個優勢是不需要擴展庫的支持,這種特性使得NuSoap可以用于所有的PHP環境,

方法一:直接調用

 

復制代碼 代碼如下:

<? 
/******************************************************************************/
/*  文件名 : 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';

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 4p嗯啊巨肉寝室调教男男视频 | 韩国美女一区 | 国产精品一品二区三区四区18 | 欧美成人一二三区 | 精品一区二区三区在线播放 | 最新日韩一区 | 成人羞羞在线观看网站 | 久草在线高清视频 | 亚洲啊v在线观看 | www.成人免费 | 国产精品久久久久久久久久久久久久久久 | 国产精品久久久久网站 | 成人免费在线网 | 成人在线免费视频播放 | 国产一区二区视频网站 | 色七七久久影院 | 成人免费一区二区 | 九九午夜视频 | 欧美日本在线视频 | 免费网站看v片在线a | 久久亚洲激情 | 久久精品国产99久久久古代 | 成人免费视频视频在线观看 免费 | 国产精品久久久久久模特 | 欧美黄色片一级 | 久久久成人精品 | 亚洲男人的天堂在线视频 | 国产精品久久久久久久久久东京 | 久久精品79国产精品 | 动漫孕妇被羞羞视频 | 宅男噜噜噜66国产在线观看 | 欧洲黄色一级视频 | 久久人人爽人人爽人人片av高清 | 国产亚洲精品久久久久久久 | 九九色网站 | 国产一区视频免费观看 | 91丨九色丨国产在线观看 | 久久福利在线 | 国产精品久久久久久久久久久久久久久久 | 成人毛片在线免费观看 | 青青草成人免费视频在线 |