Passion/Programming

SOAP 따라하기 - 2탄 예제 이해하기

sunshout 2007. 6. 21. 20:34
12.4 Debugging SOAP Web Services

예제를 바탕으로 실제 어떤 데이터들이 움직이는지 알아보자.


(Language : python)
  1. from SOAPpy import SOAPProxy
  2. url = 'http://services.xmethods.net:80/soap/servlet/rpcrouter'
  3. n = 'urn:xmethods-Temperature'
  4. server = SOAPProxy(url, namespace=n)
  5. server.config.dumpSOAPOut = 1
  6. server.config.dumpSOAPIn = 1
  7. print temperature = server.getTemp('27502')

5,6 번 줄을 보면 실제 클라이언트와 서버간의 데이터를 보겠다는 설정이다.


결과 화면 (Language : text)
  1. *** Outgoing SOAP ******************************************************
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
  4.   xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
  5.   xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
  6.   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  7.   xmlns:xsd="http://www.w3.org/1999/XMLSchema">
  8. <SOAP-ENV:Body>
  9. <ns1:getTemp xmlns:ns1="urn:xmethods-Temperature" SOAP-ENC:root="1">
  10. <v1 xsi:type="xsd:string">27502</v1>
  11. </ns1:getTemp>
  12. </SOAP-ENV:Body>
  13. </SOAP-ENV:Envelope>
  14. ************************************************************************
  15. *** Incoming SOAP ******************************************************
  16. <?xml version='1.0' encoding='UTF-8'?>
  17. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  18.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  19.   xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  20. <SOAP-ENV:Body>
  21. <ns1:getTempResponse xmlns:ns1="urn:xmethods-Temperature"
  22.   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  23. <return xsi:type="xsd:float">80.0</return>
  24. </ns1:getTempResponse>
  25.  
  26. </SOAP-ENV:Body>
  27. </SOAP-ENV:Envelope>
  28. ************************************************************************
  29.  
  30. >>> temperature
  31. 80.0

Outgoing SOAP은 클라이언트에서 서버로 보내는 xml(즉 request) 이고,
Incomming SOAP은 서버에서 request에 대해서  reply를 하는 xml이다.

결과 화면의 9~11번 라인을 제외하고는 Outgoing SOAP은 대부분이 동일하다.
그러니 9~11 번 줄의 내용이 중요하다는 말이겠지? (ns 는 namespace의 약자이다)
즉 9~11줄이 서버로 부르는 function call의  핵심 이다.

(Language : text)
  1. <ns1:getTemp
  2.     xmlns:ns1="urn:xmethods-Temperature"
  3.     SOAP-ENC:root="1">
  4. <v1 xsi:type="xsd:string">27502</v1>
  5. </ns1:getTemp>


내용을 다시 보면 ns1:getTemp라는 구조 안에 모든 데이터가 존재한다.
1번 줄에서는 getTemp라는 function name을 부른다는 것을 추측할 수 있다.
2번은 그 function과 관련된 내용일거 같고
4번 줄을 보면 해당 function call을 할 때 넘어가는 파라메터임을 추측할 수 있다.
그리고 파라메터의 타입이 string일 것이다.

이렇게 간 Outgoing SOAP 은 서버에서 요청을 처리하여 클라이언트로 리턴값을 전달하게 된다.

이 때도 역시 xml을 사용하여 데이터를 전달하게 된다.

(Language : text)
  1. <ns1:getTempResponse
  2.     xmlns:ns1="urn:xmethods-Temperature"
  3.     SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  4. <return xsi:type="xsd:float">80.0</return>
  5. </ns1:getTempResponse>

여기서도 대충 보면 ns라고 나온 내용만 보면 된다. 나머지는 형식적인 내용들이다.

서버에서 처리된 결과는 ns1:getTempResponse라는 데이터(xml 형식)로 반환되는 것을 알 수 있다.
여기서 getTempResponse라는 단어가 중요한 것이 아니라 ns1이라는 네임스페이스 중요하다.
4번 줄에는 return값을 기록하여져 있는데 타입은 float이고 값은 80.0임을 알 수 있다.