XML 비누
- SOAP는 S imple O bject A access Protocol 을 나타 냅니다 .
- SOAP는 애플리케이션 통신 프로토콜입니다.
- SOAP는 메시지를 보내고 받는 형식입니다.
- SOAP는 플랫폼에 독립적입니다.
- SOAP는 XML을 기반으로 합니다.
- SOAP는 W3C 권장 사항입니다.
왜 SOAP인가?
웹 응용 프로그램이 인터넷을 통해 통신할 수 있는 것은 중요합니다.
HTTP는 모든 인터넷 브라우저와 서버에서 지원되기 때문에 응용 프로그램 간에 통신하는 가장 좋은 방법은 HTTP를 사용하는 것입니다. 이를 수행하기 위해 SOAP가 만들어졌습니다.
SOAP는 서로 다른 기술과 프로그래밍 언어를 사용하여 서로 다른 운영 체제에서 실행되는 응용 프로그램 간에 통신하는 방법을 제공합니다.
SOAP 빌딩 블록
SOAP 메시지는 다음 요소를 포함하는 일반 XML 문서입니다.
- XML 문서를 SOAP 메시지로 식별하는 Envelope 요소
- 헤더 정보를 포함하는 Header 요소
- 호출 및 응답 정보를 포함하는 Body 요소
- 오류 및 상태 정보를 포함하는 Fault 요소
위의 모든 요소는 SOAP 봉투의 기본 네임스페이스에서 선언됩니다.
http://www.w3.org/2003/05/soap-envelope/
SOAP 인코딩 및 데이터 유형의 기본 네임스페이스는 다음과 같습니다.
http://www.w3.org/2003/05/soap-encoding
구문 규칙
다음은 몇 가지 중요한 구문 규칙입니다.
- SOAP 메시지는 XML을 사용하여 인코딩되어야 합니다.
- SOAP 메시지는 SOAP Envelope 네임스페이스를 사용해야 합니다.
- SOAP 메시지에는 DTD 참조가 포함되어서는 안 됩니다.
- SOAP 메시지에는 XML 처리 지침이 포함되어서는 안 됩니다.
스켈레톤 SOAP 메시지
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
...
</soap:Header>
<soap:Body>
...
<soap:Fault>
...
</soap:Fault>
</soap:Body>
</soap:Envelope>
SOAP 봉투 요소
필수 SOAP Envelope 요소는 SOAP 메시지의 루트 요소입니다. 이 요소는 XML 문서를 SOAP 메시지로 정의합니다.
예시
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
...
Message information goes here
...
</soap:Envelope>
xmlns:soap 네임스페이스
위의 예에서 xmlns:soap 네임스페이스에 주목하십시오. 항상 "http://www.w3.org/2003/05/soap-envelope/" 값을 가져야 합니다.
네임스페이스는 봉투를 SOAP 봉투로 정의합니다.
다른 네임스페이스를 사용하는 경우 애플리케이션은 오류를 생성하고 메시지를 삭제합니다.
encodingStyle 속성
encodingStyle 속성은 문서에 사용되는 데이터 유형을 정의하는 데 사용됩니다. 이 속성은 모든 SOAP 요소에 나타날 수 있으며 요소의 내용과 모든 하위 요소에 적용됩니다.
SOAP 메시지에는 기본 인코딩이 없습니다.
통사론
soap:encodingStyle="URI"
예시
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
...
Message information goes here
...
</soap:Envelope>
SOAP 헤더 요소
선택적 SOAP 헤더 요소에는 SOAP 메시지에 대한 애플리케이션별 정보(예: 인증, 지불 등)가 포함되어 있습니다.
Header 요소가 있는 경우 Envelope 요소의 첫 번째 자식 요소여야 합니다.
참고: Header 요소의 모든 직계 자식 요소는 네임스페이스로 한정되어야 합니다.
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
<m:Trans xmlns:m="https://www.w3schools.com/transaction/"
soap:mustUnderstand="1">234
</m:Trans>
</soap:Header>
...
...
</soap:Envelope>
위의 예에는 "Trans" 요소가 있는 헤더, 값이 1이고 값이 234인 "mustUnderstand" 속성이 포함되어 있습니다.
SOAP는 기본 네임스페이스에 세 가지 속성을 정의합니다. 이러한 속성은 mustUnderstand, Actor 및 encodingStyle입니다.
SOAP 헤더에 정의된 속성은 수신자가 SOAP 메시지를 처리하는 방법을 정의합니다.
mustUnderstand 속성
SOAP mustUnderstand 속성은 헤더 항목이 수신자가 처리할 필수 항목인지 선택 항목인지를 나타내는 데 사용할 수 있습니다.
Header 요소의 자식 요소에 mustUnderstand="1"을 추가하면 헤더를 처리하는 수신자가 요소를 인식해야 함을 나타냅니다. 수신자가 요소를 인식하지 못하면 헤더를 처리할 때 실패합니다.
통사론
soap:mustUnderstand="0|1"
예시
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
<m:Trans xmlns:m="https://www.w3schools.com/transaction/"
soap:mustUnderstand="1">234
</m:Trans>
</soap:Header>
...
...
</soap:Envelope>
액터 속성
SOAP 메시지는 메시지 경로를 따라 다른 끝점을 전달하여 발신자에서 수신자로 이동할 수 있습니다. 그러나 SOAP 메시지의 모든 부분이 궁극적인 끝점을 위한 것이 아니라 메시지 경로에 있는 하나 이상의 끝점을 위한 것일 수 있습니다.
SOAP 액터 속성은 헤더 요소를 특정 끝점으로 지정하는 데 사용됩니다.
통사론
soap:actor="URI"
예시
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
<m:Trans xmlns:m="https://www.w3schools.com/transaction/"
soap:actor="https://www.w3schools.com/code/">234
</m:Trans>
</soap:Header>
...
...
</soap:Envelope>
encodingStyle 속성
encodingStyle 속성은 문서에 사용되는 데이터 유형을 정의하는 데 사용됩니다. 이 속성은 모든 SOAP 요소에 나타날 수 있으며 해당 요소의 내용과 모든 하위 요소에 적용됩니다.
SOAP 메시지에는 기본 인코딩이 없습니다.
통사론
soap:encodingStyle="URI"
SOAP 본문 요소
필수 SOAP 본문 요소에는 메시지의 궁극적인 끝점을 위한 실제 SOAP 메시지가 포함되어 있습니다.
SOAP Body 요소의 직계 자식 요소는 네임스페이스로 한정될 수 있습니다.
예시
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<m:GetPrice xmlns:m="https://www.w3schools.com/prices">
<m:Item>Apples</m:Item>
</m:GetPrice>
</soap:Body>
</soap:Envelope>
위의 예는 사과 가격을 요청합니다. 위의 m:GetPrice 및 Item 요소는 애플리케이션별 요소입니다. SOAP 네임스페이스의 일부가 아닙니다.
SOAP 응답은 다음과 같을 수 있습니다.
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<m:GetPriceResponse xmlns:m="https://www.w3schools.com/prices">
<m:Price>1.90</m:Price>
</m:GetPriceResponse>
</soap:Body>
</soap:Envelope>
SOAP 오류 요소
선택적 SOAP Fault 요소는 오류 메시지를 표시하는 데 사용됩니다.
SOAP Fault 요소는 SOAP 메시지에 대한 오류 및 상태 정보를 보유합니다.
Fault 요소가 있는 경우 Body 요소의 자식 요소로 나타나야 합니다. Fault 요소는 SOAP 메시지에서 한 번만 나타날 수 있습니다.
SOAP Fault 요소에는 다음과 같은 하위 요소가 있습니다.
Sub Element | Description |
---|---|
<faultcode> | A code for identifying the fault |
<faultstring> | A human readable explanation of the fault |
<faultactor> | Information about who caused the fault to happen |
<detail> |
Holds application specific error information related to the Body element |
SOAP 오류 코드
아래에 정의된 오류 코드 값은 오류를 설명할 때 오류 코드 요소에 사용되어야 합니다.
Error | Description |
---|---|
VersionMismatch | Found an invalid namespace for the SOAP Envelope element |
MustUnderstand | An immediate child element of the Header element, with the mustUnderstand attribute set to "1", was not understood |
Client | The message was incorrectly formed or contained incorrect information |
Server | There was a problem with the server so the message could not proceed |
HTTP 프로토콜
HTTP는 TCP/IP를 통해 통신합니다. HTTP 클라이언트는 TCP를 사용하여 HTTP 서버에 연결합니다. 연결을 설정한 후 클라이언트는 서버에 HTTP 요청 메시지를 보낼 수 있습니다.
POST /item HTTP/1.1
Host: 189.123.255.239
Content-Type: text/plain
Content-Length: 200
그런 다음 서버는 요청을 처리하고 HTTP 응답을 다시 클라이언트로 보냅니다. 응답에는 요청 상태를 나타내는 상태 코드가 포함되어 있습니다.
200 OK
Content-Type: text/plain
Content-Length: 200
위의 예에서 서버는 상태 코드 200을 반환했습니다. 이것은 HTTP의 표준 성공 코드입니다.
서버가 요청을 디코딩할 수 없는 경우 다음과 같은 결과가 반환되었을 수 있습니다.
400 Bad Request
Content-Length: 0
SOAP 바인딩
SOAP 사양은 교환 방법이 아니라 SOAP 메시지의 구조를 정의합니다. 이 간격은 "SOAP 바인딩"으로 채워집니다. SOAP 바인딩은 SOAP 메시지가 전송 프로토콜을 사용하여 효과적으로 교환될 수 있도록 하는 메커니즘입니다.
대부분의 SOAP 구현은 HTTP 또는 SMTP와 같은 일반적인 전송 프로토콜에 대한 바인딩을 제공합니다.
HTTP는 동기식이며 널리 사용됩니다. SOAP HTTP 요청은 적어도 두 개의 HTTP 헤더(Content-Type 및 Content-Length)를 지정합니다.
SMTP는 비동기식이며 최후의 수단이나 특정 경우에 사용됩니다.
SOAP의 Java 구현은 일반적으로 JMS(Java Messaging System) 프로토콜에 대한 특정 바인딩을 제공합니다.
컨텐츠 타입
SOAP 요청 및 응답에 대한 Content-Type 헤더는 메시지에 대한 MIME 유형과 요청 또는 응답의 XML 본문에 사용되는 문자 인코딩(선택 사항)을 정의합니다.
통사론
Content-Type: MIMEType; charset=character-encoding
예시
POST /item HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
콘텐츠 길이
SOAP 요청 및 응답에 대한 Content-Length 헤더는 요청 또는 응답 본문의 바이트 수를 지정합니다.
통사론
Content-Length: bytes
예시
POST /item HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 250
SOAP 예
아래 예에서는 GetStockPrice 요청이 서버로 전송됩니다. 요청에는 StockName 매개변수와 응답에서 반환될 Price 매개변수가 있습니다. 함수의 네임스페이스는 "http://www.example.org/stock"에 정의되어 있습니다.
SOAP 요청:
POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
SOAP 응답:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>