[php] Codeigniter & Nusoap 을 이용한 webservice 구축
Codeigniter 사용법.
PHP와 잠시 이별 한뒤 오랜만에 만질 일이 있어 이왕 하는김에 제대로 해보자 생각해서
Codeigniter까지 사용해 보려 설치 해 보았다. ( 대충 자바의 Spring Framework와 비슷한 성향을 가지고 있는듯 하다. )
Codeigniter Download URL : http://ellislab.com/codeigniter/download
Nusoap Download URL : http://sourceforge.net/projects/nusoap/files/latest/download
Step 1. Codeigniter 설치.
설치법이라 할것은 별로 없다. 그냥 document_root에 압축 풀어주는 정도로 끝난다.
참 쉽다. 그리고 나서 아래 경로의 정보를 바꿔준다.
application/config/config.php
$config['base_url'] = 'rocksea.tistory.com'; // 2014.01.20 by rocksea
application/config/database.php
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'rocksea'; // 2014.01.20 by rocksea
$db['default']['password'] = 'rocksea'; // 2014.01.20 by rocksea
$db['default']['database'] = 'rocksea'; // 2014.01.20 by rocksea
$db['default']['dbdriver'] = 'mysql';
Step 2. Nusoap 설치.
이것 역시 설치라고 할 것이 없다. 그냥 압축만 풀어서 application/libraries/ 안에만 두면 된다.
폴더구조
application/libraries/NuSOAP
application/libraries/NuSOAP/lib
application/libraries/NuSOAP/samples
<?
class Nusoap_library
{
function Nusoap_library()
{
require_once('lib/nusoap'.EXT);
}
}
?>
application/controllers/webservice.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Webservice extends CI_Controller {
function Webservice()
{
parent::__construct();
$ns = 'http://'.$_SERVER['HTTP_HOST'].'/index.php/soapserver/';
$this->load->library("NuSOAP/nusoap_library"); // load nusoap toolkit library in controller
$this->nusoap_server = new soap_server(); // create soap server object
$this->nusoap_server->configureWSDL("SOAP Server Using NuSOAP in CodeIgniter", $ns); // wsdl cinfiguration
$this->nusoap_server->wsdl->schemaTargetNamespace = $ns; // server namespace
$this->nusoap_server->register("hello", array('name'=>'xsd:string'), array('return'=>'xsd:string'));
}
public function index()
{
function hello($name)
{
return "Hello $name";
}
$this->nusoap_server->service(file_get_contents("/var/www/tm/application/controllers/test.txt")); // read raw data from request body
}
}
?>
이제 WSDL 생성 유무를 확인해 보도록 하자.
쉽게 만들어 지는걸 확인 할 수 있다.
JAVA로 Verizon Callcenter API를 개발 할때도 webservice를 구축했던 기억이 난다. 그때도 maven을 이용해서 엄청 편하게
개발 한 기억이 나는데 PHP가 더 편하게 만들 수 있게 잘 지원되는 듯 하다!
.by rocksea