Memo/PHP/SOAP
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
[[Memo/PHP]]
*SOAPを使う [#c5c2c1c3]
#contents
/////////////////////////////////////////////////////////...
**PEAR版 [#wcdca806]
***インストール [#b2f3916e]
Windows版PHP 4.3.10にインストールしてみた。~
C:\php\>pear install SOAP-beta
downloading SOAP-0.8.1.tgz ...
Starting to download SOAP-0.8.1.tgz (69,177 bytes)
.................done: 69,177 bytes
requires package `Mail_Mime'
requires package `HTTP_Request'
requires package `Net_URL'
requires package `Net_DIME'
SOAP: Dependencies failed
依存関係でエラー。必要パッケージをチェック
pear info パーケージ名
バージョンが古いと言われたら
pear upgrade パーケージ名
必要パッケージのインストール
pear install Mail_Mime
pear install Net_URL
pear install HTTP_Request
pear install Net_DIME-beta
pear install SOAP-beta
Fedora Core 1の場合は、上記以外にアップグレードが必要だっ...
pear upgrade Net_Socket
これで無事インストール完了。
***SOAPサーバーの作成 [#t9205823]
「sayHello('名前')」という関数を作成してみる。~
名前を引数に渡すと「Hello 名前」と呼んでくれる簡単なもの。~
wsdlも勝手に作成してくれるので便利。~
|~wsdlの位置を知らせてくれる|[[hello_server.php>root:php/...
|~wsdl|[[hello_server.php?wsdl>root:php/soap/hello_server...
hello_server.php
<?php
require_once 'SOAP/Server.php';
// Your class
class HelloServer {
var $__dispatch_map = array();
function HelloServer() {
// Define the signature of the dispatch map
$this->__dispatch_map['sayHello'] =
array('in' => array('inputString' => 'string...
'out' => array('outputString' => 'stri...
);
}
// Required function by SOAP_Server
function __dispatch($methodname) {
if (isset($this->__dispatch_map[$methodname]))
return $this->__dispatch_map[$methodname];
return NULL;
}
// Your function
function sayHello($inputString)
{
return 'Hello '.$inputString;
}
}
// Fire up PEAR::SOAP_Server
$server = new SOAP_Server;
// Fire up your class
$helloServer = new HelloServer();
// Add your object to SOAP server (note namespace)
$server->addObjectMap($helloServer,'urn:HelloServer');
// Handle SOAP requests coming is as POST data
if (isset($_SERVER['REQUEST_METHOD']) &&
$_SERVER['REQUEST_METHOD']=='POST') {
$server->service($HTTP_RAW_POST_DATA);
} else {
// Deal with WSDL / Disco here
require_once 'SOAP/Disco.php';
// Create the Disco server
$disco = new SOAP_DISCO_Server($server,'HelloServer');
header("Content-type: text/xml");
if (isset($_SERVER['QUERY_STRING']) &&
strcasecmp($_SERVER['QUERY_STRING'],'wsdl')==0) {
echo $disco->getWSDL(); // if we're talking http...
} else {
echo $disco->getDISCO();
}
exit;
}
?>
***SOAPクライアントを作成 [#ab6c86ce]
SOAPサーバーにある、「sayHello()」関数を呼んでみる。~
-[[hello_client.php>root:php/soap/hello_client.php]]~
<?php
require_once 'SOAP/Client.php';
// Modify the URL here - note the "?wsdl" at the end
$url = 'http://' . $_SERVER["HTTP_HOST"] . dirname($_SER...
$wsdl = new SOAP_WSDL ($url);
$helloClient = $wsdl->getProxy();
echo ( $helloClient->sayHello('Bill') );
?>
***郵便番号検索Webサービスを使用してみる。[#tb6c8d47]
|~WSDL|http://nile.esm.co.jp:8080/wsdl/ZIPSearch.wsdl|
検索には数秒要するが結果を表示できた。~
-[[zip.php>root:php/soap/zip.php]]~
<?
require_once('SOAP/Client.php');
?>
<form action="<? echo $PHP_SELF?>" method="get">
<input type="radio" name="type" value="zipcode" checked>...
<input type="radio" name="type" value="address">住所
<input type="text" name="query" value="<?php echo isset(...
<input type="submit">
</form>
<?php
if (!isset($_GET["type"])) exit(1);
$query = mb_convert_encoding(trim($_GET["query"]), "utf-...
$type = trim($_GET["type"]);
$g_WSDL = "http://nile.esm.co.jp:8080/wsdl/ZIPSearch.wsd...
/**
* プロキシの作成
*/
$wsdl = new SOAP_WSDL($g_WSDL);
$proxy = $wsdl->getProxy();
$result = array();
if($type == "zipcode"){
$result = $proxy->getAddressByZipcode($query);
}else{
$result = $proxy->getZipcodeByAddress($query);
}
if(!is_array($result)){ // 配列じゃなきゃ失敗
echo "該当なし。<br>\n";
return;
}
foreach($result as $key=>$val){
// echo mb_convert_encoding($key, mb_internal_encoding()...
echo mb_convert_encoding($val, mb_internal_encoding(), ...
}
?>
***注意点 [#u9f356d9]
-入出力の文字エンコードはUTF-8で行う。~
mb_convert_encoding()を用いる。~
-戻り値の型がStructの場合は、配列や ArrayObject としてキ...
[[ハタさんのブログ : phpのstdClassと連想配列>http://blog....
var_export( (array)$response );
/////////////////////////////////////////////////////////...
*関連リンク [#y9ab5013]
-[[http://www.phppatterns.com/docs/develop/pear_soap_serv...
-[[W3Cの仕様書等の文書の日本語訳集>http://www.w3.org/Cons...
-SOAP 1.1 W3C Note
--[[原文>http://www.w3.org/TR/soap/]]
--[[日本語訳>http://www.research.ibm.com/trl/projects/xml...
-[[ネイティブ XML Web サービスでのデータ型マッピング>http...
-[[Google APIs>http://code.google.com/]]~
現在、アカウントは取れるがライセンスキーが送られてこない...
-[[Amazon Webサービス>http://www.amazon.co.jp/gp/feature....
-[[Webサービス同好会>http://objectclub.esm.co.jp/webservi...
-[[XML Webサービス対応三省堂デイリーコンサイス体験版>http...
終了行:
[[Memo/PHP]]
*SOAPを使う [#c5c2c1c3]
#contents
/////////////////////////////////////////////////////////...
**PEAR版 [#wcdca806]
***インストール [#b2f3916e]
Windows版PHP 4.3.10にインストールしてみた。~
C:\php\>pear install SOAP-beta
downloading SOAP-0.8.1.tgz ...
Starting to download SOAP-0.8.1.tgz (69,177 bytes)
.................done: 69,177 bytes
requires package `Mail_Mime'
requires package `HTTP_Request'
requires package `Net_URL'
requires package `Net_DIME'
SOAP: Dependencies failed
依存関係でエラー。必要パッケージをチェック
pear info パーケージ名
バージョンが古いと言われたら
pear upgrade パーケージ名
必要パッケージのインストール
pear install Mail_Mime
pear install Net_URL
pear install HTTP_Request
pear install Net_DIME-beta
pear install SOAP-beta
Fedora Core 1の場合は、上記以外にアップグレードが必要だっ...
pear upgrade Net_Socket
これで無事インストール完了。
***SOAPサーバーの作成 [#t9205823]
「sayHello('名前')」という関数を作成してみる。~
名前を引数に渡すと「Hello 名前」と呼んでくれる簡単なもの。~
wsdlも勝手に作成してくれるので便利。~
|~wsdlの位置を知らせてくれる|[[hello_server.php>root:php/...
|~wsdl|[[hello_server.php?wsdl>root:php/soap/hello_server...
hello_server.php
<?php
require_once 'SOAP/Server.php';
// Your class
class HelloServer {
var $__dispatch_map = array();
function HelloServer() {
// Define the signature of the dispatch map
$this->__dispatch_map['sayHello'] =
array('in' => array('inputString' => 'string...
'out' => array('outputString' => 'stri...
);
}
// Required function by SOAP_Server
function __dispatch($methodname) {
if (isset($this->__dispatch_map[$methodname]))
return $this->__dispatch_map[$methodname];
return NULL;
}
// Your function
function sayHello($inputString)
{
return 'Hello '.$inputString;
}
}
// Fire up PEAR::SOAP_Server
$server = new SOAP_Server;
// Fire up your class
$helloServer = new HelloServer();
// Add your object to SOAP server (note namespace)
$server->addObjectMap($helloServer,'urn:HelloServer');
// Handle SOAP requests coming is as POST data
if (isset($_SERVER['REQUEST_METHOD']) &&
$_SERVER['REQUEST_METHOD']=='POST') {
$server->service($HTTP_RAW_POST_DATA);
} else {
// Deal with WSDL / Disco here
require_once 'SOAP/Disco.php';
// Create the Disco server
$disco = new SOAP_DISCO_Server($server,'HelloServer');
header("Content-type: text/xml");
if (isset($_SERVER['QUERY_STRING']) &&
strcasecmp($_SERVER['QUERY_STRING'],'wsdl')==0) {
echo $disco->getWSDL(); // if we're talking http...
} else {
echo $disco->getDISCO();
}
exit;
}
?>
***SOAPクライアントを作成 [#ab6c86ce]
SOAPサーバーにある、「sayHello()」関数を呼んでみる。~
-[[hello_client.php>root:php/soap/hello_client.php]]~
<?php
require_once 'SOAP/Client.php';
// Modify the URL here - note the "?wsdl" at the end
$url = 'http://' . $_SERVER["HTTP_HOST"] . dirname($_SER...
$wsdl = new SOAP_WSDL ($url);
$helloClient = $wsdl->getProxy();
echo ( $helloClient->sayHello('Bill') );
?>
***郵便番号検索Webサービスを使用してみる。[#tb6c8d47]
|~WSDL|http://nile.esm.co.jp:8080/wsdl/ZIPSearch.wsdl|
検索には数秒要するが結果を表示できた。~
-[[zip.php>root:php/soap/zip.php]]~
<?
require_once('SOAP/Client.php');
?>
<form action="<? echo $PHP_SELF?>" method="get">
<input type="radio" name="type" value="zipcode" checked>...
<input type="radio" name="type" value="address">住所
<input type="text" name="query" value="<?php echo isset(...
<input type="submit">
</form>
<?php
if (!isset($_GET["type"])) exit(1);
$query = mb_convert_encoding(trim($_GET["query"]), "utf-...
$type = trim($_GET["type"]);
$g_WSDL = "http://nile.esm.co.jp:8080/wsdl/ZIPSearch.wsd...
/**
* プロキシの作成
*/
$wsdl = new SOAP_WSDL($g_WSDL);
$proxy = $wsdl->getProxy();
$result = array();
if($type == "zipcode"){
$result = $proxy->getAddressByZipcode($query);
}else{
$result = $proxy->getZipcodeByAddress($query);
}
if(!is_array($result)){ // 配列じゃなきゃ失敗
echo "該当なし。<br>\n";
return;
}
foreach($result as $key=>$val){
// echo mb_convert_encoding($key, mb_internal_encoding()...
echo mb_convert_encoding($val, mb_internal_encoding(), ...
}
?>
***注意点 [#u9f356d9]
-入出力の文字エンコードはUTF-8で行う。~
mb_convert_encoding()を用いる。~
-戻り値の型がStructの場合は、配列や ArrayObject としてキ...
[[ハタさんのブログ : phpのstdClassと連想配列>http://blog....
var_export( (array)$response );
/////////////////////////////////////////////////////////...
*関連リンク [#y9ab5013]
-[[http://www.phppatterns.com/docs/develop/pear_soap_serv...
-[[W3Cの仕様書等の文書の日本語訳集>http://www.w3.org/Cons...
-SOAP 1.1 W3C Note
--[[原文>http://www.w3.org/TR/soap/]]
--[[日本語訳>http://www.research.ibm.com/trl/projects/xml...
-[[ネイティブ XML Web サービスでのデータ型マッピング>http...
-[[Google APIs>http://code.google.com/]]~
現在、アカウントは取れるがライセンスキーが送られてこない...
-[[Amazon Webサービス>http://www.amazon.co.jp/gp/feature....
-[[Webサービス同好会>http://objectclub.esm.co.jp/webservi...
-[[XML Webサービス対応三省堂デイリーコンサイス体験版>http...
ページ名: