本文目錄一覽:
如何使用PHP調用ArcGIS Server的Soap介面
前一陣子,簡單的學習了一下ArcGIS Server,在開發層次上ArcGIS Server支持兩種協議,一個是老的Soap協議,也就是webservice,另外一種是REST協議,其中REST協議是從ArcGIS Server9.3開始支持的協議,也是ESRI今後只要支持的協議,但是老的Soap協議還繼續支持。該章得內容主要介紹如何使用PHP來調用ArcGIS Server的WebService。
查看ArcGIS Server的SOAP SDK的幫助的時候,會發現所提供的示例代碼只有c#,vb.net和java的,並沒有PHP語言的示例,實際上並不是不支持PHP語言,從PHP toolkits include PHP-SOAP and NuSOAP上可以看出PHP是支持Soap協議的,只不過使用PHP並沒有提供現成的工具可以將WSDL轉換成本地化的類,而.NET SDK提供了Wsdl.exe工具,java提供了Apache Axis工具可以將WSDL中的類型轉換成本地化類。
當使用PHP調用WebService的時候,當輸入的參數是簡單數據類型的時候是沒有任何問題的,返回值類型是類得時候也沒有任何的問題,但是當輸入參數的值類型為某個類得時候,就無法調用了,這些類太多了,自己手寫這些類幾乎是不可能,因此找到一個類似於Wsdl.exe和Apache Axis的工具還是很有必要的,在網上終於搜到一個工具,名字為wsdl2php.php可以實現該功能,其代碼如下所示:
// +————————————————————————+
// | wsdl2php |
// +————————————————————————+
// | Copyright (C) 2005 Knut Urdalen |
// +————————————————————————+
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
// | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
// | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
// | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
// | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
// | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
// | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
// | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
// +————————————————————————+
// | This software is licensed under the LGPL license. For more information |
// | see |
// +————————————————————————+
ini_set(‘soap.wsdl_cache_enabled’, 0); // disable WSDL cache
//if( $_SERVER[‘argc’] != 2 ) {
// die(“usage: wsdl2php /n”);
//}
$wsdl = “liuf:8399/arcgis/services/catchment/MapServer?wsdl”;
print “Analyzing WSDL”;
try {
$client = new SoapClient($wsdl);
} catch(SoapFault $e) {
die($e);
}
print “.”;
$dom = DOMDocument::load($wsdl);
print “.”;
// get documentation
$nodes = $dom-getElementsByTagName(‘documentation’);
$doc = array(‘service’ = ”,
‘operations’ = array());
foreach($nodes as $node) {
if( $node-parentNode-localName == ‘service’ ) {
$doc[‘service’] = trim($node-parentNode-nodeValue);
} else if( $node-parentNode-localName == ‘operation’ ) {
$operation = $node-parentNode-getAttribute(‘name’);
//$parameterOrder = $node-parentNode-getAttribute(‘parameterOrder’);
$doc[‘operations’][$operation] = trim($node-nodeValue);
}
}
print “.”;
// get targetNamespace
$targetNamespace = ”;
$nodes = $dom-getElementsByTagName(‘definitions’);
foreach($nodes as $node) {
$targetNamespace = $node-getAttribute(‘targetNamespace’);
}
print “.”;
// declare service
$service = array(‘class’ = $dom-getElementsByTagNameNS(‘*’, ‘service’)-item(0)-getAttribute(‘name’),
‘wsdl’ = $wsdl,
‘doc’ = $doc[‘service’],
‘functions’ = array());
print “.”;
// PHP keywords – can not be used as constants, class names or function names!
$reserved_keywords = array(‘and’, ‘or’, ‘xor’, ‘as’, ‘break’, ‘case’, ‘cfunction’, ‘class’, ‘continue’, ‘declare’, ‘const’, ‘default’, ‘do’, ‘else’, ‘elseif’, ‘enddeclare’, ‘endfor’, ‘endforeach’, ‘endif’, ‘endswitch’, ‘endwhile’, ‘eval’, ‘extends’, ‘for’, ‘foreach’, ‘function’, ‘global’, ‘if’, ‘new’, ‘old_function’, ‘static’, ‘switch’, ‘use’, ‘var’, ‘while’, ‘array’, ‘die’, ‘echo’, ’empty’, ‘exit’, ‘include’, ‘include_once’, ‘isset’, ‘list’, ‘print’, ‘require’, ‘require_once’, ‘return’, ‘unset’, ‘__file__’, ‘__line__’, ‘__function__’, ‘__class__’, ‘abstract’, ‘private’, ‘public’, ‘protected’, ‘throw’, ‘try’);
php soap 如何設置超時?
在使用soap前,先檢查soap的url是否可訪問。如為true則繼續執行Soap,否則給出超時提醒。
下面是我經常使用的判斷網站鏈接是否可用的函數,希望對你有用。
//判斷URL在指定時間內是否有相應
function checkUrl($url, $timeout = 3){
$ret = false;
$handle = curl_init();
curl_setopt($handle, CURLOPT_URL,$url);
curl_setopt($handle, CURLOPT_NOBODY, true);
curl_setopt($handle, CURLOPT_TIMEOUT,$timeout);//設置默認超時時間為3秒
$result = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
if(strpos($httpCode,’2′) == 0){
$ret = true;
}
return $ret;
}
如何給soap添加header頭 php
使用php 設置soapHeader時要如下進行,不然發出去的包會變成類似「itemkeyuser/keyvalue23107720/value/item」的格式: $auth_header = array( ‘user’=$key, ‘password’=$pwd ); // 下面的RequestSOAPHeader 對應 wsdl 定義裡面的 xsd:element name=”RequestSOAPHeader”….. $authvalues = new SoapVar($auth_header, SOAP_ENC_OBJECT,”RequestSOAPHeader”,$uri); $header = new SoapHeader($uri, ‘RequestSOAPHeader’, $authvalues); $api = new SoapClient(null,$options); $api-__setSoapHeaders(array($header));不明白的話可以去後盾人看看相關的教學視頻。
請大神指教用php發送SOAP請求
使用PHP中的soap類進行soap請求,請求的數據要跟wsdl中的數據類型一致,返回的數據也是由WSDL中定義好了的按照定義去取數據即可。
原創文章,作者:AJYX,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/144187.html