一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

淺談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ù)轉(zhuǎn)為數(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ù)轉(zhuǎn)為數(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';

  至此應該是一切正常了才對,但是我們在輸出結(jié)果的時候,卻發(fā)現(xiàn)返回的是亂碼。
  NuSoap調(diào)用WebService出現(xiàn)亂碼的解決方法:
  實際上,開啟了調(diào)試功能的朋友,相信會發(fā)現(xiàn)$client->response返回的是正確的結(jié)果,為什么$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思路及源碼分享,轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: 婷婷在线免费观看 | 精品久久久久久久 | 亚洲欧美日韩精品在线 | 国产夫妻精品 | 国产短视频精品区第一页 | 国产91精品高清一区二区三区 | 男人女人的免费视频网站 | h成人在线 | 国产91在线精品福利 | 国产精品视频国产永久视频 | 色播在线观看免费 | 精品四虎免费观看国产高清 | 成年人视频在线 | 国产真实伦视频在线观看 | 亚洲另类图 | 国产一区二区中文字幕 | 中国麻豆 | 欧美极品第一页 | 国产精品影视 | 久久er精品热线免费 | 色涩在线| 国产真实伦正在播放 | 免费无遮挡毛片 | 美女精品一区二区 | 黄色影院在线观看视频 | 91视频免费观看网站 | 国产乱码一区二区三区四川人 | 日本护士xxxxx18.19 | 激情五月亚洲 | 中文字幕在线有码高清视频 | 中文字幕一区二区三区永久 | 好吊操视频在线 | 亚洲综合色网站 | 黄色网免费观看 | 一本伊人 | 国产网站在线 | 黄色小视频在线观看免费 | 男人猛桶女人下面视频国产 | 国产精品欧美久久久久天天影视 | 精品视频在线免费观看 | 天天视频免费入口 |