Posted on 2008/10/22 15:42
Filed Under Development/PHP



폴더 구조

Zend Framework 1.6.2
/libraries/Zend

xmlrpc 메인
/xmlrpc
    server_test.php   --> 서버파일
    client_test.php    --> 클라이언트 파일

서비스 파일들
/xmlrpc/Services
    Test.php   --> 서비스 파일


server_test.php
<?php
//Zend Framework 1.6.2
set_include_path('../libraries/');
//기본 Zend_Xmlrpc_Server 관련 파일들 
require_once 'Zend/XmlRpc/Server.php';
require_once 'Zend/XmlRpc/Server/Cache.php';
//서비스 클래스들
require_once 'Services/Test.php';
//server 인스턴스 생성
$server = new Zend_XmlRpc_Server() ;
//서비스 정의
$server->setClass('Services_Test', 'test');
//값 출력
echo $server->handle() ;
?>


client_test.php
<?php
//Zend Framework 1.6.2
set_include_path('../libraries/');
require 'Zend/XmlRpc/Client.php';
$client = new Zend_XmlRpc_Client('http://localhost/xmlrpc/server_test.php'); 
 
try { 
$result = $client->call('test.add', array(5, 7));
}
catch ( Zend_XmlRpc_Client_HttpException $e )
{
    echo "HTTP Exception ". $e->getCode() .":". $e->getMessage();
    exit ;
}
catch ( Zend_XmlRpc_Client_FaultException $e )
{
    echo "XML-RPC FaultException ". $e->getCode() ." : ". $e->getMessage();
    exit ;
}
echo 'result : ' . $result;
?>


중요한것... 메소드에 코드블럭을 반드시 달아야 동작함
Test.php
<?php
/**
 * xmlrpc 테스트 클래스
 * 
 * 메소드나 함수의 phpdoc 스타일 주석을 꼭 달아야 한다.
 *
 */
class Services_Test {
/**
* TODO : 코드 블럭을 달아야 동작함
* 간단한 두 값을 받아 더해 리턴하는 메소드
*
* @param int $value1 첫번째 값
* @param int $value2 두번째 값
* @return int 두값을 더한 값
*/
function add($value1, $value2) {
return $value1 + $value2;
}
}
?>
2008/10/22 15:42 2008/10/22 15:42
TAG : , , ,

트랙백 주소 : http://www.takeone.pe.kr/trackback/206

Counter

· Total
: 361645
· Today
: 93
· Yesterday
: 110