小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

PHP5 擴(kuò)展SOAP 調(diào)用 webservice

 躍來躍去 2011-02-12

php4時(shí)代調(diào)用webservice大部分使用的nusoap。到了php5已經(jīng)有了自己的soap擴(kuò)展。所以可以完全的拋棄nusoap這個(gè)許久沒有更新過的東西了。

因?yàn)槟壳笆潜镜亻_發(fā)需要。只說windows下的。

配置環(huán)境

windows下找到php安裝目錄下的php.ini。打開后編輯。找到

extension=php_soap.dll

然后將前面的;號(hào)去掉。

然后就是寫一個(gè)php文件來驗(yàn)證一下。

實(shí)例程序

在apache的htdocs目錄下創(chuàng)建ws.php

代碼如下:

<?php
header("content-type:text/html;charset=utf-8");
try {
$client = new SoapClient( 'http://erp./SendSMS/Service.asmx?wsdl',array('trace' => true, 'exceptions' => true ));
var_dump($client->__getFunctions());
} catch (SOAPFault $e) {
print_r($e);
}
?>

在瀏覽器中輸入:http://localhost/ws.php后會(huì)出現(xiàn)

array
0 => string 'SendSMSResponse SendSMS(SendSMS $parameters)' (length=44)
1 => string 'SendSMS1Response SendSMS1(SendSMS1 $parameters)' (length=47)
2 => string 'SendMailResponse SendMail(SendMail $parameters)' (length=47)
3 => string 'IsSendSMSResponse IsSendSMS(IsSendSMS $parameters)' (length=50)
4 => string 'IsSendSMS1Response IsSendSMS1(IsSendSMS1 $parameters)' (length=53)
5 => string 'SendSMSResponse SendSMS(SendSMS $parameters)' (length=44)
6 => string 'SendSMS1Response SendSMS1(SendSMS1 $parameters)' (length=47)
7 => string 'SendMailResponse SendMail(SendMail $parameters)' (length=47)
8 => string 'IsSendSMSResponse IsSendSMS(IsSendSMS $parameters)' (length=50)
9 => string 'IsSendSMS1Response IsSendSMS1(IsSendSMS1 $parameters)' (length=53)

現(xiàn)在逐行解釋一下。$client = new SoapClient( 'http://erp./SendSMS/Service.asmx?wsdl',array('trace' => true, 'exceptions' => true ));
這里的SoapClient類可以作為給定的ws的客戶端。這個(gè)SoapClient有兩種操作模式。
一個(gè)是WSDL模式,一個(gè)是Non-WSDL模式。
當(dāng)然這里用的是WSDL模式。所以重點(diǎn)來說第一種。
WSDL模式中,SoapClient的構(gòu)造參數(shù)分別是ws的請(qǐng)求地址以及各種請(qǐng)求配置參數(shù)。
var_dump($client->__getFunctions());
這里就是訪問后輸出的這個(gè)接口可提供的方法,返回值以及參數(shù)。
那么如何去調(diào)用方法呢。

<?php
header("content-type:text/html;charset=utf-8");
try {
$client = new SoapClient( 'http://erp./SendSMS/Service.asmx?wsdl',
array('trace' => true, 'exceptions' => true ));
var_dump($client->__getFunctions());
//第一個(gè)參數(shù)是命名空間,第二個(gè)參數(shù)是SoapHeader頭的類名,第三個(gè)是SoapHeader參數(shù)的數(shù)組可以寫成array
$v = array("Token"=>"");
$headers = new SoapHeader("http:///","AuthenticationHeader",$v, false, SOAP_ACTOR_NEXT);
$client->__setSoapHeaders(array($headers));
//$types = $client->__getTypes(); //這里是為了查看方法的類型
  //print_r($types);
//這里就是根據(jù)方法參數(shù)的需要虛擬出來一個(gè)sms類型的數(shù)組
$sms1 = array(
'Id'=>100000,
'SjNo'=>'13512222222',
'UnickName'=>'tuangou',
'SmsContent'=>'test',
'Type'=>1000,
'OrderIdString'=>'1231114567'
);
$param = array(
'sms1'=>$sms1
);
//這里是需要注意到地方。調(diào)用方法的參數(shù)必須是一個(gè)數(shù)組。而且默認(rèn)以parameters字段標(biāo)識(shí)為參數(shù)數(shù)組。真正的參數(shù)都要放在$param變量中。
$return = $client->__soapCall("SendSMS1",array('parameters'=>$param));
print_r($return);
} catch (SOAPFault $e) {
print_r('Exception:'.$e);
}
?>
POST /SendSMS/Service.asmx HTTP/1.1
Host: erp.
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http:///SendSMS1"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www./2001/XMLSchema-instance" xmlns:xsd="http://www./2001/XMLSchema" xmlns:soap="http://schemas./soap/envelope/">
<soap:Header>
<AuthenticationHeader xmlns="http:///">
<Token>string</Token>
</AuthenticationHeader>
</soap:Header>
<soap:Body>
<SendSMS1 xmlns="http:///">
<sms1>
<Id>int</Id>
<SjNo>string</SjNo>
<UnickName>string</UnickName>
<SmsContent>string</SmsContent>
<Type>int</Type>
<OrderIdString>string</OrderIdString>
</sms1>
</SendSMS1>
</soap:Body>
</soap:Envelope>

這里可以看到。soap的Header和Body。Header里就是Token。Body里就是具體的方法了。

SendSMS1節(jié)點(diǎn)是方法名。

sms1節(jié)點(diǎn)就是參數(shù)。

sms1節(jié)點(diǎn)下的就是參數(shù)的屬性。

一定要按照順序?qū)傩赃M(jìn)行逐個(gè)賦值。



    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多