NuSOAP 시작하기

1 개요[ | ]

NuSOAP 시작하기
NuSOAP 튜토리얼, NuSOAP 설치
  • PHP용 SOAP 도구
  • 서버+클라이언트 기능 둘다 들어있음

2 nusoap 다운로드[ | ]

3 설치[ | ]

[root@zetawiki vendor]# ll nusoap-0.9.5.zip 
-rw-r--r-- 1 root root 182035 Aug 20 10:04 nusoap-0.9.5.zip
  • 하위폴더 만들고 압축해제
[root@zetawiki vendor]# mkdir nusoap
[root@zetawiki vendor]# unzip nusoap-0.9.5.zip -dnusoap
Archive:  nusoap-0.9.5.zip
  inflating: nusoap/lib/changelog    
  inflating: nusoap/lib/class.nusoap_base.php  
... (생략)
  inflating: nusoap/samples/wsdlclient7.php  
  inflating: nusoap/samples/wsdlclient8.php  
  inflating: nusoap/samples/wsdlclient9.php

4 실습용 폴더 생성[ | ]

[root@zetawiki vendor]# cd /var/www/html/
[root@zetawiki html]# mkdir -p ex/soap
[root@zetawiki html]# cd ex/soap/
[root@zetawiki soap]#

5 nusoap-server.php[ | ]

<?php
require_once 'vendor/nusoap/lib/nusoap.php';

$server = new nusoap_server();
$server->soap_defencoding = 'UTF-8';

$server->configureWSDL('Welcome');
$server->register("sayHello", array('name'=>'xsd:string'), array('return'=>'xsd:string'));
$server->register("sayAnnyeong", array('name'=>'xsd:string'), array('return'=>'xsd:string'));

function sayHello($name) {
	return "Hello, $name!";
}
function sayAnnyeong($name) {
	return "안녕, $name!";
}

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);

6 nusoap-client.php[ | ]

server.php와 client.php는 서로 다른 서버에 두는 것이 당연하겠지만, 실습이므로 한 폴더에 두고 테스트해보자.

<?php
require_once 'vendor/nusoap/lib/nusoap.php';

$client = new nusoap_client("http://zetawiki.com/ex/soap/nusoap-server.php?wsdl");
$client->decode_utf8 = false;

$result = $client->call('sayAnnyeong', array('name'=>'John Smith'));
print_r($result);
// 안녕, John Smith!

7 nusoap-client-debug.php[ | ]

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

<?php
require_once 'vendor/nusoap/lib/nusoap.php';
function xmp($arr) { echo '<xmp>'; print_r($arr); echo '</xmp>'; }

$client = new nusoap_client('http://zetawiki.com/ex/soap/nusoap-server.php?wsdl');
$client->decode_utf8 = false;

$result = $client->call('sayAnnyeong', array('name'=>'John Smith'));
$err = $client->getError();
if($client->fault) {
	echo 'Fault: '; xmp($result);
	return;
}
if($err) {
	echo 'Error: '; xmp($err);
	return;
}

echo 'OK: '; xmp($result);
echo '<h2>Request</h2>'; xmp(str_replace(">",">\n",$client->request));
echo '<h2>Response</h2>'; xmp(str_replace(">",">\n",$client->response));

8 같이 보기[ | ]

9 참고[ | ]

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