PHP5中的SOAP方法
server.php
<?php function getQuote { global $dbh;$result = array;try {$query = "SELECT fprice, fcansale, fbalance,
fbaltip FROM tblbalance where upper)
= :psep limit 1";$stmt = $dbh->prepare;$stmt->execute)));$stmt->bindColumn;$stmt->bindColumn;$stmt->bindColumn;$stmt->bindColumn;while) {//}} catch {echo $e->getMessage;}return $fprice; //你可以返回一个数组}
$dsn = ’pgsql:host=192.168.*.*
port=5432 dbname=db user=123456 password=123456’;try {$dbh = new PDO;} catch {die); }ini_set; // disabling WSDL cache $server = new SoapServer; //配置文件$server->addFunction; $server->handle; ?>
stockquote.wsdl
<?xml version =’1.0’ encoding =’UTF-8’ ?>
<definitions name=’StockQuote’
targetNamespace=’http://example.org/StockQuote’
xmlns:tns=’http://example.org/StockQuote’
xmlns:soap=’http://schemas.xmlsoap.org/wsdl/soap/’
xmlns:xsd=’http://www.w3.org/2001/XMLSchema’
xmlns:soapenc=’http://schemas.xmlsoap.org/soap/encoding/’
xmlns:wsdl=’http://schemas.xmlsoap.org/wsdl/’
xmlns=’http://schemas.xmlsoap.org/wsdl/’>
<message name=’getQuoteRequest’>
<part name=’symbol’ type=’xsd:string’/>
</message>
<message name=’getQuoteResponse’>
<part name=’Result’ type=’xsd:float’/>
</message>
<portType name=’StockQuotePortType’>
<operation name=’getQuote’>
<input message=’tns:getQuoteRequest’/>
<output message=’tns:getQuoteResponse’/>
</operation>
</portType>
<binding name=’StockQuoteBinding’ type=’tns:StockQuotePortType’>
<soap:binding style=’rpc’
transport=’http://schemas.xmlsoap.org/soap/http’/>
<operation name=’getQuote’>
<soap:operation soapAction=’urn:xmethods-delayed-quotes#getQuote’/>
<input>
<soap:body use=’enpd’ namespace=’urn:xmethods-delayed-quotes’
encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/>
</input>
<output>
<soap:body use=’enpd’ namespace=’urn:xmethods-delayed-quotes’
encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/>
</output>
</operation>
</binding>
<service name=’StockQuoteService’>
<port name=’StockQuotePort’ binding=’StockQuoteBinding’>
<soap:address location=’http://192.168.3.9/php5/server.php’/>
</port>
</service>
</definitions>
client.php
·CURL方法
·SOCKET方法
·PHP5中的SOAP方法
以下分别给出示例来达成它:
echo "OK," . $fh3seh3 . "," . $fbalance ;//以逗号分隔
SOCKET方法
这个要借用第三方类库HttpClient,可以到这里下载:http://scripts.incutio.com/httpclient/
CURL方法
client.php
<?php$psep = ’NDE005’;$website = ’www.abc.com’;$amt = 1;$pwd = 123456;$ch = curl_init;$curl_url = "http://ics1.server.com/index.php?web=" . $website . "&pwd=" . $pwd . "&action=check&pseid=" . $psep . "&amt=" . $amt;curl_seTOPt;curl_seTOPt;curl_seTOPt;//不直接输出,返回到变量$curl_result = curl_exec;$result = explode;curl_close;print_r;?>
服务器端仅需按肯定的格式输出,然后推广客户端按此格式接收就好了如:
<?php$psep = ’NDE005’;$website = ’www.abc.com’;$amt = 1;$pwd = 123456;$ch = curl_init;$curl_url = "http://ics1.server.com/index.php?web=" . $website . "&pwd=" . $pwd . "&action=check&pseid=" . $psep . "&amt=" . $amt;curl_seTOPt;curl_seTOPt;curl_seTOPt;//不直接输出,返回到变量$curl_result = curl_exec;$result = explode;curl_close;print_r;?>
服务器端仅需按肯定的格式输出,然后推广客户端按此格式接收就好了如:
echo "OK," . $fpsep . "," . $fbalance ;//以逗号分隔
SOCKET方法
这个要借用第三方类库HttpClient,可以到这里下载:http://scripts.incutio.com/httpclient/
<?phprequire_once ’class/HttpClient.php’;$params = array;$pageContents = HttpClient::quickPost;$result = explode;print_r;?>
PHP5中的SOAP方法
server.php
<?php function getQuote { global $dbh;$result = array;try {$query = "SELECT fprice, fcansale, fbalance,
fbaltip FROM tblbalance where upper)
= :psep limit 1";$stmt = $dbh->prepare;$stmt->execute)));$stmt->bindColumn;$stmt->bindColumn;$stmt->bindColumn;$stmt->bindColumn;while) {//}} catch {echo $e->getMessage;}return $fprice; //你可以返回一个数组}
$dsn = ’pgsql:host=192.168.*.*
port=5432 dbname=db user=123456 password=123456’;try {$dbh = new PDO;} catch {die); }ini_set; // disabling WSDL cache $server = new SoapServer; //配置文件$server->addFunction; $server->handle; ?>
stockquote.wsdl
<?xml version =’1.0’ encoding =’UTF-8’ ?>
<definitions name=’StockQuote’
targetNamespace=’http://example.org/StockQuote’
xmlns:tns=’http://example.org/StockQuote’
xmlns:soap=’http://schemas.xmlsoap.org/wsdl/soap/’
xmlns:xsd=’http://www.w3.org/2001/XMLSchema’
xmlns:soapenc=’http://schemas.xmlsoap.org/soap/encoding/’
xmlns:wsdl=’http://schemas.xmlsoap.org/wsdl/’
xmlns=’http://schemas.xmlsoap.org/wsdl/’>
<message name=’getQuoteRequest’>
<part name=’symbol’ type=’xsd:string’/>
</message>
<message name=’getQuoteResponse’>
<part name=’Result’ type=’xsd:float’/>
</message>
<portType name=’StockQuotePortType’>
<operation name=’getQuote’>
<input message=’tns:getQuoteRequest’/>
<output message=’tns:getQuoteResponse’/>
</operation>
</portType>
<binding name=’StockQuoteBinding’ type=’tns:StockQuotePortType’>
<soap:binding style=’rpc’
transport=’http://schemas.xmlsoap.org/soap/http’/>
<operation name=’getQuote’>
<soap:operation soapAction=’urn:xmethods-delayed-quotes#getQuote’/>
<input>
<soap:body use=’enpd’ namespace=’urn:xmethods-delayed-quotes’
encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/>
</input>
<output>
<soap:body use=’enpd’ namespace=’urn:xmethods-delayed-quotes’
encodingStyle=’http://schemas.xmlsoap.org/soap/encoding/’/>
</output>
</operation>
</binding>
<service name=’StockQuoteService’>
<port name=’StockQuotePort’ binding=’StockQuoteBinding’>
<soap:address location=’http://192.168.3.9/php5/server.php’/>
</port>
</service>
</definitions>
client.php
<?php $client = new SoapClient; $result = $client->getQuote; print_r;?>