출처: http://egloos.zum.com/tequiero35/v/1026372
※ 웹 서비스 구조
※ SOAP (Simple Object Access Protocol)
: 분산 환경에서 어플리케이션 간에 정보를 교환하기 위한 XML 기반의 메시지 프로토콜.
- 상호 운영성(Interoperability) : 서로 다른 인프라를 바탕으로 컴포넌트를 연결하는 표준이 필요
⊙ SOAP Part 구조
1. 요 청 (Request)
Request = Request-Line * (general-header | request-header | entity-header) CRLF [message-body] |
POST /axis/services/axisTest HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1.4 Host: 127.0.0.1:1234 Cache-Control: no-cache Pragma: no-cache SOAPAction: "" Content-Length: 934 |
▷ Method
◦ POST
메시지의 entity body에 포함되어 있는 자원을 Request-Line에 있는 Request-URI에 지정되어 있는 대로 서버에서 수용해달라고 요청할 때 쓰인다
HTTP/1.0의 모든 POST 요구 메시지에는 Content-Length가 반드시 있어야 하며, 서버가 이에 대한 정보를 확보하지 못하게 되면 400 (Bad Request) 메시지를 응답해야 한다.
▷ Header Field
◦ Content-Length
Entity-Body의 크기를 바이트 단위로 표시하여 수신측에게 알려주는 용도.
◦ Content-Type
수신측에게 전달하는 Entity-Body의 데이타 형식을 표시한다. (MIME)
◦ Pragma
general-header 필드. request/response chain을 따라 어떤 수신측에도 적용할 수 있는 구현 방식에 한정된 지시자(implementation-specific)를 포함하는 데 사용한다
"no-cache" 변수가 요구 메시지에 존재한다면 응용 프로그램에서는 해당 자원이 캐시되어 있을지라도 원래 위치하고 있는 서버로 요구 메시지를 전달해야 한다. 이것은 클라이언트가 보내는 요구에 대해 신뢰할 수 있는 응답을 받고자 할 때 쓰일 수 있으며, 또한 클라이언트에게 데이타 오류와 같이 문제가 발생한 캐시 문서를 갱신할 수 있도록 할 때 쓰일 수 있다.
◦ Cache-Control
브라우저나 프록시 서버로 하여금 요청시에 캐시된 문서를 사용하지 말고 매번 서버로부터 새로운 문서를 다시 전송받아 사용하도록 알리는 헤더.
HTTP1.0 에서는 Pragma 헤더에 'no-cache'를, HTTP1.1 에서는 Cache-Control 헤더에 'no-cache'를 각각 지정함으로써 가능하다.
◦ User-Agent
사용자가 요구 메시지를 생성시키는 브라우저에 대한 정보를 나타낸다.
◦ Host
request-header 필드. 자원의 인터넷 호스트와 포트 숫자를 명시.
◦ Accept
request-header 필드. 요구에 대한 응답 메시지로서 허용할 수 있는 media type 범위를 알려줄 때 사용한다.
"type/*" 표시는 해당 type에 대한 모든 종류의 subtype 형식을 허용한다는 뜻.
◦ Date
메시지가 만들어지는 날짜와 시간
2. 응 답 (Response)
Response = Status-Line * (general-header | request-header | entity-header) CRLF [message-body] |
HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/xml;charset=utf-8 Date: Mon, 19 Nov 2007 Connection: close |
▷ 상태 코드 (Status Code)
◦ Informational 1xx
임시적인 응답을 의미. Status-Line과 선택적인 헤더들로 구성되어 빈줄로서 끝을 나타낸다.
◦ Successful 2XX
클라이언트의 요구가 성공적으로 수신되어 처리되었다는 것을 의미.
- 200 OK
클라이언트의 요구가 서버에서 성공적으로 처리되었음.
◦ Redirection 3xx
해당 요구를 수행하기 위해 추가적인 동작이 필요
◦ Client Error 4xx
클라이언트에 의해 생긴 오류 상황들에 대해 사용한다.
◦ Server Error 5xx
서버에게 일어난 오류상황이나 요구 사항을 처리할 수 없을 때.
⊙ SOAP Part 구조
▷ <env:Envelop>
◦ 루트 엘리먼트
◦ SOAP 메시지를 위한 네임스페이스
- SOAP 네임스페이스 : http://schemas.xmlsoap.org/soap/envelope/
- XML Schema 네임스페이스 : http://www.w3.org/2001/XMLSchema
- XML Schema 인스턴스 네임스페이스 : http://www.w3.org/2001/XMLSchema-instance
- 데이터 타입 인코딩 네임스페이스
: http://schemas.xmlsoap.org/soap/encoding/
◦ SOAP 버전
- SOAP 의 Envelope 엘리먼트는 명시적으로 프로토콜의 버전을 표현하지 않는다.
- 대신 XML 네임스페이스의 능력을 증대시키고, SOAP envelope namespace 의 URI가 되기 위한 프로토콜의버전을 정의한다.
◦ 예제
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
▷ <env:Header>
◦ <env:Envelop> 엘리먼트의 하위 엘리먼트.
◦ SOAP 메시지 처리하는데 필요한 추가 정보를 기술한다. (인증 정보, 세션, 트랜잭션 등)
◦ Header 요소를 사용하는 경우
1) 인증 (Authentication)
: 수신받은 메시지를 사용하기 전 허가된 전송자가 송신한 메시지인지 확인해야 하는 경우 사용한다.
2) 보안 (Sercurity degest information)
: 메시지를 수신하는 입장에서는 수신메시지가 훼손되지 않은 상태임을 보장받고 싶어한다.
이 경우, 전송자는 디지털 서명을 메시지 본문에 전송하고 digest 를 헤더에 포함해 보낸다.
3) 정보 라우팅 (Routing information)
: 메시지를 전송해야 할 곳이 많다면 헤더에 그 리스트 및 순서를 포함할 수 있다.
4) 트랜잭션 (Transaction)
: 메시지를 수신한 쪽에서 어떤 행위를 수행할 때 송신측의 트랜잭션 범주 내에 포함되어야 하는 경우 사용한다.
5) 지불 정보 (Payment information)
: 서비스 호출 단위로 그 사용료를 지불하는 경우라면 지불 정보 수집에 필요한 정보를 헤더에 포함시킬 수 있다.
◦ Attribute
1) actor
- 해당 Header 블록을 누가 처리해야 하는지 지정.
- 지정된 경우 : actor 어트리뷰트에 지정된 노드가 SOAP Header 블록을 처리
- 지정되지 않은 경우 : SOAP 메시지의 최종 수신자가 처리
2) mustUnderstand
- Header에 포함된 내용이 반드시 처리되어야 하는지 지정.
- 값이 1 일 때 : 반드시 처리
- 값이 0 일 때 : 처리하지 않아도 무방.
3)
◦ 예제
<env:Header xmlns:t="http://example.org/2001/06/tx"> <t:Transaction actor="http://example.org/2001/06/tx"> 5 </t:Transaction> <t:authentication mustUnderstand="1"> <t:userName>Tom</t:userName> <t:password>12345678</t:password> </t:authentication> </env:Header> |
▷ <env:Body>
◦ Web Service 를 이용하기 위한 실제 메시지 기술.
- 서비스 호출, 응답에 관련된 내용
- 웹 서비스 수행 후, 에러 있을 때 SOAP Fault 를 기술한다.
◦ Attribute
1) encodingStyle : 인코딩 타입 지정.
- 데이터 타입이 사용된 엘리먼트의 어트리뷰트로 선언한다.
- SOAP 1.1 의 인코딩 규칙 : http://schemas.xmlsoap.org/encoding/
- SOAP 1.2 의 인코딩 규칙 : http://www.w3.org/2001/09/soap-encoding
◦ 예제
<soapenv:Body> <ns1:example soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://classArrayTest.ex"> <in0 soapenc:arrayType="xsd:int[2]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> <in0 href="#id0"/> <in0 href="#id1"/> </in0> </ns1:example> <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">4</multiRef> <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">9</multiRef> </soapenv:Body> |
▷ <env:Fault>
◦ <env:Body> 엘리먼트의 하위 엘리먼트.
◦ SOAP 문서 처리 할 때 에러가 발생할 경우, 그 내용을 기술한다.
Sub Element | Description |
<faultcode> | required. SOAP 스펙에 정의된 fault 코드. (아래 fault code 참조) |
<faultstring> | required. 사람이 읽을 수 있는 fault에 대한 설명. |
<faultactor> | optional. 누구에 의해 야기된 fault 인지에 대한 정보. 에러가 발생한 노드 기술. |
<detail> | optional. Body 엘리먼트에 관계된 application specific 에러 정보를 기술. |
◦ 작성 예제
<env:Body> <env:Fault> <faultcode>MustUnderstand</faultcode> <faultstring>One or more mandatory headers not understood</faultstring> </env:Fault> |
예제1) SOAP_request.txt
POST /axis/services/axisTest HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1.4 Host: 127.0.0.1:1234 Cache-Control: no-cache Pragma: no-cache SOAPAction: "" Content-Length: 934 <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <ns1:example soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://classArrayTest.ex"> <in0 soapenc:arrayType="xsd:int[2]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> <in0 href="#id0"/> <in0 href="#id1"/> </in0> </ns1:example> <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">4</multiRef> <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">9</multiRef> </soapenv:Body> </soapenv:Envelope> |
HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/xml;charset=utf-8 Date: Mon, 19 Nov 2007 05:53:00 GMT Connection: close <?xml version="1.0" encoding="utf-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <ns1:exampleResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://classArrayTest.ex"> <exampleReturn href="#id0"/> </ns1:exampleResponse> <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:A" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://classArrayTest.ex"> <a href="#id1"/> <b href="#id2"/> </multiRef> <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">9</multiRef> <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">4</multiRef> </soapenv:Body></soapenv:Envelope> |
◦ fault code
Error | Description |
VersionMismatch | 요쳥 SOAP Envelope 엘리먼트의 네임스페이스가 잘못된 것을 발견한 경우. |
MustUnderstand | |
Client | 발신자의 요청 SOAP 메시지 정보가 불충분하여 처리할 수 없는 경우. |
Server | 수신자(server)에서 SOAP 메시지를 처리하는 도중 오류가 발생한 경우. |
<REFERENCE>
http://blog.naver.com/semi7623?Redirect=Log&logNo=100005637477