2013년 4월 23일 화요일

SOAP이란


SOAP (Simple Object Access Protocol)

출처 : http://tequiero35.egloos.com/1026372

강좌 : http://www.w3schools.com/soap/default.asp

What is SOAP?

분산 환경에서 어플리케이션 간에 정보를 교환하기 위한 XML 기반의 메시지 프로토콜.

  • SOAP stands for Simple Object Access Protocol
  • SOAP is a communication protocol
  • SOAP is for communication between applications
  • SOAP is a format for sending messages
  • SOAP communicates via Internet
  • SOAP is platform independent
  • SOAP is language independent
  • SOAP is based on XML
  • SOAP is simple and extensible
  • SOAP allows you to get around firewalls
  • SOAP is a W3C recommendation

Why SOAP?

It is important for application development to allow Internet communication between programs.
Today's applications communicate using Remote Procedure Calls (RPC) between objects like DCOM and CORBA, but HTTP was not designed for this.
RPC represents a compatibility and security problem; firewalls and proxy servers will normally block this kind of traffic.
A better way to communicate between applications is over HTTP, because HTTP is supported by all Internet browsers and servers. SOAP was created to accomplish this.
SOAP provides a way to communicate between applications running on different operating systems, with different technologies and programming languages.


SOAP 구조

SOAPPart 구조HTTP

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필드. 자원의 인터넷 호스트와 포트 숫자를 명시. ◦ Acceptrequest-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 05:53:00 GMT
Connection: close

▷ 상태 코드 (Status Code)

◦ Informational 1xx
임시적인 응답을 의미. Status-Line과 선택적인 헤더들로 구성되어 빈줄로서 끝을 나타낸다.

Successful 2XX
클라이언트의 요구가 성공적으로 수신되어 처리되었다는 것을 의미.
- 200 OK
클라이언트의 요구가 서버에서 성공적으로 처리되었음.

Redirection 3xx
해당 요구를 수행하기 위해 추가적인 동작이 필요

◦ Client Error 4xx
클라이언트에 의해 생긴 오류 상황들에 대해 사용한다.

◦ Server Error 5xx
서버에게 일어난 오류상황이나 요구 사항을 처리할 수 없을 때.


SOAPPart 구조



<env:Envelop>

◦ 루트 엘리먼트
SOAP메시지를 위한 네임스페이스
-XML Schema네임스페이스 : http://www.w3.org/2001/XMLSchema
-XML Schema인스턴스 네임스페이스 : http://www.w3.org/2001/XMLSchema-instance
-데이터 타입 인코딩 네임스페이스
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문서 처리 할 때 에러가 발생할 경우, 그 내용을 기술한다.


fault 엘리먼트의 서브 엘리먼트.
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></env:Body>


◦ fault code
Error
Description
VersionMismatch
요쳥 SOAP Envelope 엘리먼트의 네임스페이스가 잘못된 것을 발견한 경우.
MustUnderstand
mustUnderstand 애트리뷰트 값이 "1"로 셋팅된 (Header 엘리먼트의 자식) 엘리먼트를 처리하지 못했다.
Client
발신자의 요청 SOAP 메시지 정보가 불충분하여 처리할 수 없는 경우.
The message was incorrectly formed or contained incorrect information
Server
수신자(server)에서 SOAP 메시지를 처리하는 도중 오류가 발생한 경우.

<REFERENCE>
소설같은XML & XML Web Services웹서비스+기본개념+이해-pres_de_toi.ppt
http://www.w3schools.com/soap/soap_fault.asp

[웹 서비스] 3. SOAP 메시지 : http://blog.naver.com/vhwani/30021637109  (원 출처 : XML 웹 서비스 (신민철 저/프리렉) )

댓글 없음:

댓글 쓰기