extension=php_xmlrpc.dll아파치 2 서버를 재시작하여 SOAP 및 XML-RPC 확장기능을 활성화한다. SOAP 확장기능은 SOAP 1.1, SOAP 1.2, WSDL 1.1 명세의 서브셋(subset)들을 지원한다.
extension=php_soap.dll
메소드 | 설명 |
---|---|
SoapServer->__construct( mixed wsdl [, array options] ) | SoapServer 객체를 생성한다. wsdl 파라미터에는 WSDL의 URI를 지정한다. SOAP 버전과 같은 SoapServer 옵션은 options 배열에 지정할 수 있다. |
SoapServer->addFunction( mixed functions ) | SOAP 요청을 처리할 하나 이상의 PHP 함수를 추가한다. 추가할 함수가 한 개일 경우에는 문자열로 추가할 수 있다. 하나 이상의 함수는 배열로 추가한다. |
SoapServer->fault() | 오류를 의미하는 SoapServer 장애 |
SoapServer->getFunctions() | 함수의 목록을 반환한다. |
SoapServer->handle() | SOAP 요청을 처리하며, 필요한 함수를 호출하고 응답을 돌려보낸다. |
SoapServer->setClass(string class_name [, mixed args [, mixed ...]] ) | SOAP 요청을 처리할 클래스를 지정하며, 지정된 클래스로부터 모든 메소드를 내보낸다. args는 기본 클래스 생성자에 의해 사용된다. |
SoapHeader->__construct() | SOAP 헤더를 생성한다. |
SoapClient->__soapCall( string function_name, array arguments [, array options [, mixed input_headers [, array &output_headers]]] ) | SOAP 함수를 호출한다. |
SoapClient->__doRequest() | SOAP 요청을 수행한다. |
SoapClient->__getFunctions() | SOAP 함수의 목록을 반환한다. |
SoapClient->__getTypes() | SOAP 타입의 목록을 반환한다. |
엘리먼트 | 설명 |
---|---|
definitions | 웹 서비스에 의해 교환되는 메시지의 자료형에 대한 정의를 지정한다. 권장되는 타입 시스템은 XML 스키마이다. |
message | 전송되는 데이터를 정의한다. 메시지는 하나 혹은 그 이상의 파트(part)들로 이루어진다. 파트는 타입과 연관된다. |
portType | 오퍼레이션의 집합과 각 오퍼레이션에 대한 입출력 메시지를 정의한다. |
operation | 서비스에 의해 지원되는 동작(메소드). 각 오퍼레이션들은 입출력 메시지로 이루어진다. |
input | 요청에 대한 메시지 형식을 지정한다. |
output | 응답에 대한 메시지 형식을 지정한다. |
binding | 오퍼레이션에 대한 메시지 형식과 프로토콜 세부사항 및 특정 portType에 대한 메시지를 정의한다. |
service | 포트들의 집합을 지정한다. |
port | 바인딩을 통해 주소를 연결하여 종단을 정의한다. |
<?xml version ='1.0' encoding ='UTF-8' ?>catalog.wsdl 문서를 PHP 스크립트가 실행되고 있는 C:Apache2htdocs 디렉터리로 복사한다. soap-server.php라는 이름의 PHP 스크립트를 작성하여 CatalogService 웹 서비스에서 제공되는 오퍼레이션을 정의한다. soap-server.php 스크립트에는 catalogId를 인자로 받아들여 HTML 문서로 구성되어 있는 문자열을 반환하는 getCatalogEntry() 함수를 정의한다. 반환되는 HTML 문서의 문자열은 지정된 catalogId에 대한 카탈로그 엔트리를 구성한다.
<definitions name='Catalog'
targetNamespace='http://example.org/catalog'
xmlns:tns=' http://example.org/catalog '
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:soapenc='http://schemas.xmlsoap.org/soap/
encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
<message name='getCatalogRequest'>
<part name='catalogId' type='xsd:string'/>
</message>
<message name='getCatalogResponse'>
<part name='Result' type='xsd:string'/>
</message>
<portType name='CatalogPortType'>
<operation name='getCatalogEntry'>
<input message='tns:getCatalogRequest'/>
<output message='tns:getCatalogResponse'/>
</operation>
</portType>
<binding name='CatalogBinding' type=
'tns:CatalogPortType'>
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http'
/>
<operation name='getCatalogEntry'>
<soap:operation soapAction='urn:localhost-catalog#
getCatalogEntry'/>
<input>
<soap:body use='encoded' namespace=
'urn:localhost-catalog'
encodingStyle='http://schemas.xmlsoap.org/soap
/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace=
'urn:localhost-catalog'
encodingStyle='http://schemas.xmlsoap.org/soap/
encoding/'/>
</output>
</operation>
</binding>
<service name='CatalogService'>
<port name='CatalogPort' binding=
'CatalogBinding'>
<soap:address location='http://localhost/
soap-server.php'/>
</port>
</service>
</definitions>
function getCatalogEntry($catalogId) {기본적으로 WSDL 캐시가 활성화된다. soap.wsdl_cache_enabled 설정 옵션을 0으로 설정하여 WSDL 캐시를 비활성화한다.
if($catalogId=='catalog1')
return "<HTML> … </HTML>";
elseif ($catalogId='catalog2')
return "<HTML>…</HTML>";
}
ini_set("soap.wsdl_cache_enabled", "0");catalog.wsdl WSDL을 이용하는 SoapServer 객체를 생성한다.
$server = new SoapServer("catalog.wsdl");addFunction() 메소드를 이용하여 SoapServer 객체에 getCatalogEntry 함수를 추가한다. SOAP 웹 서비스는 getCatalogEntry 오퍼레이션을 제공한다.
$server->addFunction("getCatalogEntry");SOAP 요청을 처리한다.
$server->handle();soap-server.php 스크립트가 아래에 나타나 있다.
<?php다음 섹션에서는 SOAP 서버에 요청을 전송하는 SOAP 클라이언트를 작성해볼 것이다.
function getCatalogEntry($catalogId) {
if($catalogId=='catalog1')
return "<HTML>
<HEAD>
<TITLE>Catalog</TITLE>
</HEAD
<BODY>
<p> </p>
<table border>
<tr><th>CatalogId</th>
<th>Journal</th><th>Section
</th><th>Edition</th><th>
Title</th><th>Author</th>
</tr><tr><td>catalog1</td>
<td>IBM developerWorks</td><td>
XML</td><td>October 2005</td>
<td>JAXP validation</td>
<td>Brett McLaughlin</td></tr>
</table>
</BODY>
</HTML>";
elseif ($catalogId='catalog2')
return "<HTML>
<HEAD>
<TITLE>Catalog</TITLE>
</HEAD
<BODY>
<p> </p>
<table border>
<tr><th>CatalogId</th><th>
Journal</th><th>Section</th>
<th>Edition</th><th>Title
</th><th>Author
</th></tr><tr><td>catalog1
</td><td>IBM developerWorks</td>
<td>XML</td><td>July 2006</td>
<td>The Java XPath API
</td><td>Elliotte Harold</td>
</tr>
</table>
</BODY>
</HTML>";
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("catalog.wsdl");
$server->addFunction("getCatalogEntry");
$server->handle();
?>
SSISO Community