A fork of https://github.com/Synerty/SOAPpy-py3 This is a working tree till fixes get imported upstream.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

187 lines
5.0 KiB

  1. Getting Started
  2. ===============
  3. NEW:
  4. Mark Pilgrims' online book _Dive Into Python_ at
  5. http://diveintopython.org includes a nice tutorial for SOAPpy in
  6. Chapter 12. "SOAP Web Services" at
  7. http://diveintopython.org/soap_web_services.
  8. The easiest way to get up to speed is to run and read the scripts in the
  9. tests directory. Better documentation is coming.
  10. Here are some examples of how to use SOAPpy:
  11. CLIENT EXAMPLES:
  12. ## CODE
  13. from SOAPpy import SOAPProxy
  14. server = SOAPProxy("http://localhost:8080/")
  15. print server.echo("Hello world")
  16. ## /CODE
  17. This opens a connection to the server listening on localhost:8080, calls the
  18. method echo with the ordered parameter of "Hello World", and prints the
  19. results.
  20. ## CODE
  21. from SOAPpy import SOAPProxy
  22. server = SOAPProxy("https://localhost:8443/")
  23. print server.echo("Hello world")
  24. ## /CODE
  25. This opens a secure connection to the SSL server listening on
  26. localhost:8443, calls the method echo with the ordered parameter of
  27. "Hello World" and prints the results. Python must be built with OpenSSL.
  28. ## CODE
  29. from SOAPpy import SOAPProxy
  30. server = SOAPProxy("http://services.xmethods.com/soap",
  31. namespace = "urn:xmethods-delayed-quotes")
  32. print server.getQuote(symbol = "IBM")
  33. ## /CODE
  34. This calls method getQuote that is in the namespace URI of
  35. urn:xmethods-delayed-quotes on server services.xmethods.com. getQuote is
  36. passed a named parameter, symbol.
  37. ## CODE
  38. from SOAPpy import SOAPProxy
  39. server = SOAPProxy("http://services.xmethods.com/soap")
  40. print server._ns("urn:xmethods-delayed-quotes").getQuote(symbol = "IBM")
  41. ## /CODE
  42. This does the same thing as the previous example, however namespace is
  43. specified inline on a per call basis rather than at the server level.
  44. ## CODE
  45. from SOAPpy import SOAPProxy
  46. server = SOAPProxy("http://services.xmethods.com/soap",
  47. soapaction = "http://somesite.com/myaction")
  48. print server._ns("urn:xmethods-delayed-quotes").getQuote(symbol = "IBM")
  49. ## /CODE
  50. This is the same quote call with a soapaction specified.
  51. ## CODE
  52. from SOAPpy import SOAPProxy
  53. server = SOAPProxy("http://services.xmethods.com:80/soap")
  54. ns = "urn:xmethods-delayed-quotes")
  55. sa = "http://somesite.com/myaction"
  56. my_call = server._ns(ns)._sa(sa)
  57. my_call.getQuote(symbol = "IBM")
  58. my_call.getQuote(symbol = "IBM")
  59. my_call.getQuote(symbol = "IBM")
  60. ## /CODE
  61. The same example, this time with both the soapaction and the namespace
  62. specified inline and saved in a local variable for getQuote to be called
  63. against.
  64. ** What SOAPpy does with the results of a call could seem surprising. If
  65. there is only one element in the structType that has the return value and
  66. unwrap_results is turned on (the default) it will bubble up the single
  67. attribute, otherwise it will return you a structType object with all of the
  68. attributes.
  69. SERVER EXAMPLES:
  70. ## CODE
  71. from SOAPpy import SOAPServer
  72. def echo(s):
  73. return s + s # repeats a string twice
  74. server = SOAPServer(("localhost", 8080))
  75. server.registerFunction(echo)
  76. server.serve_forever()
  77. ## /CODE
  78. This exposes the function echo (that takes an unnamed arguement) on a server
  79. running on localhost:8080.
  80. ## CODE
  81. from SOAPpy import SOAPServer
  82. def echo(s):
  83. return s + s # repeats a string twice
  84. server = SOAPServer()
  85. server.registerFunction(echo, "echo-space")
  86. server.serve_forever()
  87. ## /CODE
  88. The same as above, but this time the method is available in the namespace
  89. "echo-space".
  90. ## CODE
  91. from SOAPpy import SOAPServer
  92. class echoBuilder:
  93. def echo(self, val):
  94. return val + val
  95. server = SOAPServer()
  96. e = echoBuilder()
  97. server.registerObject(e)
  98. server.serve_forever()
  99. ## /CODE
  100. This registers the whole instance of the object echoBuilder, e. Every
  101. method of the instance is exposed on the server.
  102. ## CODE
  103. from SOAPpy import SOAPServer
  104. def echo(**kw):
  105. return kw['first'] + kw['second'] + kw['third']
  106. server = SOAPServer()
  107. server.registerKWFunction(echo)
  108. server.serve_forever()
  109. ## /CODE
  110. This time the method echo is exposed and it expects named arguments. The
  111. main thing to notice here is the use of the method registerKWFunction over
  112. registerFunction.
  113. ## CODE
  114. from SOAPpy import SOAPServer
  115. from M2Crypto import SSL
  116. def echo(s):
  117. return s+s # repeats a string twice
  118. ssl_context = SSL.Context()
  119. ssl_context.load_cert('server.pem')
  120. server = SOAPServer(("localhost",8443), ssl_context = ssl_context)
  121. server.registerFunction(echo)
  122. server.serve_forever()
  123. ## /CODE
  124. This exposes the function echo (taking an unnamed arguement) on a server
  125. accepting SSL connections at localhost:8443. Ng Pheng Siong's M2Crypto
  126. package (available at <http://www.pobox.org.sg/home/ngps/m2/>) must be
  127. installed. Also see tests/silabserver.py.
  128. $Id: GettingStarted.txt,v 1.4 2005/02/21 20:09:29 warnes Exp $