2007/10/30
최석훈
목차
I.
Distributed System
II.
SOAP
의
장점
III.
SOAP
메시지
구조
I.
Envelope
II.
Header
III.
Body
IV.
SOAP
예제
–
달력
얻기
I.
SOAP server
II.
SOAP client
III.
Fault element
Distributed System
JAVA RMI
CORBA
DCOM
•
특정
포트
사용으로
방화벽에서
차단될
수
있음
•
일반적으로
위
기술
간
호출
불가능
여러
서버에
분산된
컴포넌트간
상호
호출
가능
SOAP
의
장점
•
플랫폼
독립적
•
인간
친화적
플랫폼
및
언어에
종속되지
않고
쉽게
구현
및
사용
가능
방화벽
등의
방해
없이
거의
모든
시스템과
통신
가능
비동기식
처리로
한
방향
액션
(
퍼블리싱
등
)
처리
유용
XML
기반
SMTP
사용
HTTP
사용
SOAP
메시지
구조
<?XML VERSION="1.0" ENCODING="EUC
-
KR" ?>
<Envelope>
<!
--
Header
부분
:
생략
가능
--
>
<Header>
…
</Header>
<!
--
Body
부분
:
필수
--
>
<Body>
…
</Body>
</Envelope>
Envelope
Envelope element
루트
엘리먼트
SOAP
메시지의
네임스페이스를
지정
http://schemas.xmlsoap.org/soap/envelope/
http://www.w3.org/2003/05/soap
-
envelope/
encodingStyle attribute
어떤
식으로
메시지를
구성할
것인지
명시
http://schemas.xmlsoap.org/soap/encoding/
http://www.w3.org/2003/05/soap
-
encoding
Header
Header element
Header
의
사용은
선택
사항
SOAP
메시지를
받는
쪽에서
이를
어떻게
처리할
것
인지를
기술
여러
개의
자식
엘리먼트를
포함할
수
있음
받는
쪽에서는
해석
가능한
Header
의
자식
엘리먼트
만
해석해
수행
mustUnderstand
속성이
1
로
설정되어
있으면
반드시
해석해야
하고
,
못하면
에러를
발생해야
함
Header element
actor attribute (role attribute in SOAP 1.2)
해당
헤더를
어떤
수신자가
처리할
것인지
기술
<?XML VERSION="1.0" ENCODING="EUC
-
KR" ?>
<en:Envelope …>
<en:Header>
<au:Authentication xmlns:au="http://..."
en:actor="http://actor.com/auth"
en:mustUnderstand="1">
<id>foo</id>
<pw>1q2w3e</pw>
</au:authentication>
</en:Header>
…
</Envelope>
<?XML VERSION="1.0" ENCODING="EUC
-
KR" ?>
<en:Envelope …>
<en:Header>
<ao:AuthenticationOk xmlns:ao="http://...">
<name>Gildong, Hong.</name>
</ao:AuthenticationOk>
</en:Header>
…
</Envelope>
<actor.com
에서
처리한
결과
메시지
>
<actor.com
에서
처리될
메시지
>
Body
Body element
메시지
수신자에게
전달되어야
할
목적
정보
프로시저
요청
/
실행
결과
/
에러
등을
포함
최종
수신자가
정의한
네임스페이스를
써서
기술
WSDL
<binding …>
<soap:body … namespace="http://ns">
SOAP:Body
<en:Envelope … xmlns:ns="http://ns">
<ns:SomeMethod> … </ns:SomeMethod>
SOAP
예제
–
달력
얻기
SOAP
서버
1.
#!/usr/bin/env python
2.
3.
import sys, calendar
4.
5.
#Import the SOAP.py machinery
6.
from SOAPpy import SOAP
7.
8.
CAL_NS = "http://uche.ogbuji.net/eg/ws/simple
-
cal"
9.
10.
class Calendar:
11.
def getMonth(self, year, month):
12.
return calendar.month(year, month)
13.
14.
def getYear(self, year):
15.
return calendar.calendar(year)
16.
17.
server = SOAP.SOAPServer(("localhost", 8080))
18.
cal = Calendar()
19.
server.registerObject(cal, CAL_NS)
20.
21.
print "Starting server..."
22.
server.serve_forever()
SOAP
클라이언트
1.
import sys,
httplib
2.
3.
SERVER_ADDR = '127.0.0.1'
4.
SERVER_PORT = 8080
5.
CAL_NS = "http://uche.ogbuji.net/ws/eg/simple
-
cal"
6.
7.
BODY_TEMPLATE = """<SOAP
-
ENV:Envelope
8.
xmlns:SOAP
-
ENV="http://schemas.xmlsoap.org/soap/envelope/"
9.
xmlns:s
="http://uche.ogbuji.net/eg/ws/simple
-
cal"
10.
xmlns:xsi
="http://www.w3.org/1999/XMLSchema
-
instance"
11.
xmlns:xsd
="http://www.w3.org/1999/XMLSchema"
12.
SOAP
-
ENV:encodingStyle
="http://schemas.xmlsoap.org/soap/encoding/">
13.
<SOAP
-
ENV:Body
>
14.
<s:getMonth>
15.
<year
xsi:type
="
xsd:integer
">%s</year>
16.
<month
xsi:type
="
xsd:integer
">%s</month>
17.
</s:getMonth>
18.
</SOAP
-
ENV:Body
>
19.
</SOAP
-
ENV:Envelope
>"""
SOAP
클라이언트
(
계속
)
20.
def
GetMonth
():
21.
year = 2001
22.
month = 12
23.
body = BODY_TEMPLATE % (year, month)
24.
25.
blen
=
len
(body)
26.
requestor =
httplib.HTTP
(SERVER_ADDR, SERVER_PORT)
27.
requestor.putrequest
("POST", "cal
-
server")
28.
requestor.putheader
("Host", SERVER_ADDR)
29.
requestor.putheader
("Content
-
Type", "text/plain;
charset
=
\
"
utf
-
8
\
"")
30.
requestor.putheader
("Content
-
Length",
str
(
blen
))
31.
requestor.putheader
("
SOAPAction
", "http://uche.ogbuji.net/eg/ws/simple
-
cal")
32.
requestor.endheaders
()
33.
34.
print 'SENDED MESSAGE
---
'
35.
print body
36.
print '
-----------------
\
n'
37.
38.
requestor.send
(body)
SOAP
클라이언트
(
계속
)
HTTP headers
Accept
Specifies which Internet media types are acceptable
Content
-
Length
Indicates the size (in octets) of the entity
-
body
Content
-
Type
Specifies the Internet media type of the entity
-
body
Host
Specifies the Internet host and port number
User
-
Agent
Contains information about the user agent (client)
SOAPAction
URI or empty string("") or NULL
SOAP
클라이언트
(
계속
)
20.
def
GetMonth
():
21.
year = 2001
22.
month = 12
23.
body = BODY_TEMPLATE % (year, month)
24.
25.
blen
=
len
(body)
26.
requestor =
httplib.HTTP
(SERVER_ADDR, SERVER_PORT)
27.
requestor.putrequest
("POST", "cal
-
server")
28.
requestor.putheader
("Host", SERVER_ADDR)
29.
requestor.putheader
("Content
-
Type", "text/xml;
charset
=
\
"
utf
-
8
\
"")
30.
requestor.putheader
("Content
-
Length",
str
(
blen
))
31.
requestor.putheader
("
SOAPAction
", "http://uche.ogbuji.net/eg/ws/simple
-
cal")
32.
requestor.endheaders
()
33.
34.
print 'SENDED MESSAGE
---
'
35.
print body
36.
print '
-----------------
\
n'
37.
38.
requestor.send
(body)
SOAP
클라이언트
(
계속
)
39.
(status_code, message, reply_headers) = requestor.getreply()
40.
41.
reply_body = requestor.getfile().read()
42.
43.
print 'RECEIVED MESSAGE
---
'
44.
print "status code:", status_code
45.
print "status message:", message
46.
print "HTTP reply header:"
47.
for header in reply_headers.headers:
48.
print header,
49.
print "HTTP reply body:
\
n", reply_body
50.
print '
-------------------
'
51.
52.
if __name__ == "__main__":
53.
GetMonth()
HTTP status code
Successful 2xx
200
–
OK / 204
–
No Content
Redirection 3xx
301
–
Moved Permanently / 302
–
Found
Client Error 4xx
400
–
Bad Request / 403
–
Forbidden /
404
–
Not Found
Server Error 5xx
500
–
Internal Server Error /
503
–
Service Unavailable
SOAP
클라이언트
(
계속
)
Fault
Fault element
SOAP
메시지
처리
때
생기는
에러
정보를
처리
<Body>
엘리먼트
안에
하나만
나타날
수
있음
다음
엘리먼트를
가질
수
있음
<faultcode>
-
오류
코드
<faultstring>
-
오류
설명
<faultactor>
-
누가
오류를
발생시켰는지에
대한
정보
<detail>
-
오류에
대한
자세한
설명
SOAP fault
Reference / Q&A
석광진
외
역
,
자바를
이용한
웹
서비스
구축
.
안진만
역
, .NET XML
웹
서비스
.
김종민
외
저
, POWER XML.
송은지
외
저
,
웹
서비스
컴퓨팅
.
Quick reference to HTTP headers
The Python Web services developer: Python SOAP
libraries
SOAP Version 1.2 Part 1: Messaging Framework (Se
cond Edition)
images from
gettyimages
RF section
Enter the password to open this PDF file:
File name:
-
File size:
-
Title:
-
Author:
-
Subject:
-
Keywords:
-
Creation Date:
-
Modification Date:
-
Creator:
-
PDF Producer:
-
PDF Version:
-
Page Count:
-
Preparing document for printing…
0%
Commentaires 0
Connectez-vous pour poster un commentaire