Deep dive into Kernel
홈
태그
미디어로그
위치로그
방명록
Passion/Python
SOAP 웹서비스콜을 naive하게 부르기
sunshout
2009. 10. 21. 22:54
(Language : python)
import
sys
,
httplib
# a "as lighter as possible" soap message:
SM_TEMPLATE =
""
"<?xml version="
1.0
" encoding="
UTF
-8
"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="
http://schemas.
xmlsoap
.
org
/soap/encoding/
"
xmlns:SOAP-ENV="
http://schemas.
xmlsoap
.
org
/soap/envelope/
">
<SOAP-ENV:Body>
<ns1:readLS xmlns:ns1="
http://phonedirlux.
homeip
.
net
/
types
">
<String_1>%s</String_1>
</ns1:readLS>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
"
""
SoapMessage = SM_TEMPLATE%
(
"Your message or e-mail"
)
print
SoapMessage
#construct and send the header
webservice =
httplib
.
HTTP
(
"www.pascalbotte.be"
)
webservice.
putrequest
(
"POST"
,
"/rcx-ws/rcx"
)
webservice.
putheader
(
"Host"
,
"www.pascalbotte.be"
)
webservice.
putheader
(
"User-Agent"
,
"Python post"
)
webservice.
putheader
(
"Content-type"
,
"text/xml; charset=
\"
UTF-8
\"
"
)
webservice.
putheader
(
"Content-length"
,
"%d"
%
len
(
SoapMessage
)
)
webservice.
putheader
(
"SOAPAction"
,
"
\"
\"
"
)
webservice.
endheaders
(
)
webservice.
send
(
SoapMessage
)
# get the response
statuscode, statusmessage, header = webservice.
getreply
(
)
print
"Response: "
, statuscode, statusmessage
print
"headers: "
, header
res = webservice.
getfile
(
)
.
read
(
)
print
res
Python에서 SOAPpy를 이용하여 SOAP을 부를수도 있지만, 생성된 XML 코드가 일치하지 않아서 제대로 동작하지 않는 경우가 있다.
이를 경우에는 전달되는 SOAP 메시지를 분석하게 나이브하게 메시지를 만들고 httplib를 이용하여 메소드를 콜 할 수 있다.
공유하기
게시글 관리
Deep dive into Kernel
티스토리툴바
Deep dive into Kernel
구독하기