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

淺談PHP調(diào)用Webservice思路及源碼分享

方法一:直接調(diào)用

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

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

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

// 調(diào)用遠程函數(shù) 
$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');

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

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

// 調(diào)用遠程函數(shù)
$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;

?>

方法二:代理方式調(diào)用

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

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

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

//調(diào)用遠程函數(shù)  
$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');

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

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

//調(diào)用遠程函數(shù)
$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 調(diào)用.NET WebService或J2EE  WebService的朋友可能都遇到過中文亂碼問題,下面介紹這一問題的出現(xiàn)的原因和相應的解決方法。
  NuSoap調(diào)用WebService出現(xiàn)亂碼的原因:
  通常我們進行WebService開發(fā)時都是用的UTF-8編碼,這時我們需要設置:
復制代碼 代碼如下:
$client->soap_defencoding = 'utf-8';
$client->soap_defencoding = 'utf-8';

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

  至此應該是一切正常了才對,但是我們在輸出結果的時候,卻發(fā)現(xiàn)返回的是亂碼。
  NuSoap調(diào)用WebService出現(xiàn)亂碼的解決方法:
  實際上,開啟了調(diào)試功能的朋友,相信會發(fā)現(xiàn)$client->response返回的是正確的結果,為什么$result = $client->call($action, array('parameters' => $param)); 卻是亂碼呢?
  研究過NuSoap代碼后我們會發(fā)現(xiàn),當xml_encoding設置為UTF-8時,NuSoap會檢測decode_utf8的設置,如果為true,會執(zhí)行 php 里面的utf8_decode函數(shù),而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調(diào)用Webservice思路及源碼分享,轉載需保留來源!

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

主站蜘蛛池模板: 麻豆人妻换人妻X99 麻豆区蜜芽区 | 国产视频这里只有精品 | 精品亚洲午夜久久久久 | 竹菊精品久久久久久久99蜜桃 | 欧美片内射欧美美美妇 | 夜夜狂射影院欧美极品 | 无码丰满人妻熟妇区 | 热九九99香蕉精品品 | 国产99网站 | a在线免费观看视频 | 亚洲伊人久久网 | 久久99综合国产精品亚洲首页 | 中文无码熟妇人妻AV在线 | 日韩精品久久日日躁夜夜躁影视 | 最近在线视频观看2018免费 | 琪琪电影午夜理论片77网 | 97视频免费上传播放 | gogo亚洲肉体艺术照片9090 | 果冻传媒在线观看网站 | 中文字幕亚洲乱码熟女在线萌芽 | 国产亚洲精品久久久久苍井松 | 日韩 国产 中文 无码 | 伊人网中文字幕 | 浪荡女天天不停挨CAO日常视 | 亚洲第一成年网站视频 | adc我们的永久网址 adc网址在线观看 | 久久资源365 | 幻女FREE性俄罗斯学生 | 中文字幕亚洲欧美在线视频 | 99视频精品国产在线视频 | 亚洲欧洲日韩视频在钱 | 调教日本美女 | 亚洲日韩成人 | 亚洲国产精品无码2019 | 亞洲人妻AV無碼在線視頻 | 久久久久久久久亚洲 | 调教椅上的调教SM总裁被调教 | 国产精品久久久久婷婷五月色 | 亚洲视频精品在线观看 | 亚洲综合无码一区二区 | 嗯啊…嗯np男男双性总受 |