라이브러리
[PHP] SoapServer::addSoapHeader - 응답에 SOAP 헤더 추가
SoapServer::addSoapHeader
PHP의 SoapServer 클래스는 SOAP(Web Service) 서버를 구현하는 데 사용되는 클래스입니다. SoapServer::addSoapHeader 메소드는 SOAP 헤더를 추가하는 데 사용됩니다.
# 사용법
SoapServer::addSoapHeader 메소드는 다음과 같은 형식으로 사용됩니다.
#hostingforum.kr
php
SoapServer::addSoapHeader(string $namespace, string $name, string $value, bool $mustUnderstand = false)
- `$namespace` : SOAP 헤더의 네임스페이스입니다.
- `$name` : SOAP 헤더의 이름입니다.
- `$value` : SOAP 헤더의 값입니다.
- `$mustUnderstand` : SOAP 헤더가 이해되어야 하는지 여부입니다. 기본값은 `false`입니다.
# 예제
다음 예제는 SOAP 헤더를 추가하는 방법을 보여줍니다.
#hostingforum.kr
php
<?php
class MyService extends SoapServer {
function __construct() {
parent::__construct(null, array('uri' => 'http://example.com/myService'));
$this->addSoapHeader('http://example.com/namespace', 'MyHeader', 'Hello, World!');
}
}
$server = new MyService();
$server->handle();
?>
이 예제에서는 `MyService` 클래스의 생성자에서 `addSoapHeader` 메소드를 사용하여 SOAP 헤더를 추가합니다. 헤더의 네임스페이스는 `http://example.com/namespace`이고 이름은 `MyHeader`이며 값은 `Hello, World!`입니다.
# SOAP 헤더를 읽는 방법
SOAP 헤더를 읽는 방법은 다음과 같습니다.
#hostingforum.kr
php
<?php
class MyService extends SoapServer {
function __construct() {
parent::__construct(null, array('uri' => 'http://example.com/myService'));
}
function getHeader() {
$headers = $this->getSoapHeaders();
foreach ($headers as $header) {
if ($header->namespace == 'http://example.com/namespace' && $header->name == 'MyHeader') {
return $header->value;
}
}
return null;
}
}
$server = new MyService();
$server->handle();
echo $server->getHeader(); // Hello, World!
?>
이 예제에서는 `getHeader` 메소드를 사용하여 SOAP 헤더를 읽습니다. 헤더의 네임스페이스와 이름을 비교하여 헤더의 값을 반환합니다.
# 참고
SOAP 헤더는 SOAP 요청에 포함되어 있습니다. 헤더의 네임스페이스와 이름은 SOAP 요청의 `SOAP-ENV:Header` 요소에 포함됩니다.
#hostingforum.kr
xml
<?xml version="1.0" encoding="UTF-8"?>
Hello, World!
SOAP 헤더를 읽는 방법은 위의 예제와 같습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.