NuSOAP 시작하기

Jmnote (토론 | 기여)님의 2012년 10월 2일 (화) 16:26 판 (→‎client_debug.php)
NuSOAP 시작하기
NuSOAP 튜토리얼
  • PHP용 SOAP 도구.

1 설치

  • http://sourceforge.net/projects/nusoap/ 접속
  • [Download]
  • 기다리면 nusoap-0.9.5.zip 파일 자동 다운로드
  • 압축해제
  • 자신의 웹서버의 DOCUMENT_ROOT 아래에 soap 폴더 생성
  • lib 폴더 전체를 서버의 soap 폴더에 업로드

2 server.php

<?php
require_once('/var/www/html/nusoap/lib/nusoap.php');
$server = new nusoap_server;
$server->configureWSDL('Welcome');
$server->register("hello", array('name'=>'xsd:string'), array('return'=>'xsd:string'));
function hello($name) { return "Hello, $name!"; }
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

3 client.php

server.php와 client.php는 서로 다른 서버에 있는 경우가 많겠지만, 튜토리얼이므로 한 폴더에 두고 테스트해보자.

<?php
require_once '/var/www/html/nusoap/lib/nusoap.php';
$client = new nusoap_client("http://jmnote.com/nusoap/server.php?wsdl", true);
$result = $client->call('hello', array('name'=>'John Smith'));
print_r($result);
?>

4 client_debug.php

client.php와 기능은 같다. 오류메시지를 보여주기 때문에 디버그가 용이하다.

<?php
require_once '/var/www/html/nusoap/lib/nusoap.php';
function xmp_print_r($arr) { echo '<xmp>'; print_r($arr); echo '</xmp>'; }
$client = new nusoap_client('http://jmnote.com/nusoap/server.php?wsdl');
$result = $client->call('hello', array('name'=>'John Smith'));
$err = $client->getError();
if($client->fault) {
	echo 'Fault: '; xmp_print_r($result);
	return;
}
if($err) {
	echo 'Error: '; xmp_print_r($err);
	return;
}
echo 'OK: '; print_r($result);
echo '<h2>Request</h2>'; xmp_print_r(str_replace(">",">\n",$client->request));
echo '<h2>Response</h2>'; xmp_print_r(str_replace(">",">\n",$client->response));
?>

5 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}