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.
 
 
 
 

105 lines
2.8 KiB

  1. Using Headers
  2. =============
  3. SOAPpy has a Header class to hold data for the header of a SOAP message.
  4. Each Header instance has methods to set/get the MustUnderstand attribute, and
  5. methods to set/get the Actor attribute.
  6. SOAPpy also has a SOAPContext class so that each server method can be
  7. implemented in such a way that it gets the context of the connecting client.
  8. This includes both common SOAP information and connection information (see
  9. below for an example).
  10. CLIENT EXAMPLES
  11. ---------------
  12. ## CODE
  13. import SOAPpy
  14. test = 42
  15. server = SOAPpy.SOAPProxy("http://localhost:8888")
  16. server = server._sa ("urn:soapinterop")
  17. hd = SOAPpy.Header()
  18. hd.InteropTestHeader ='This should fault, as you don\'t understand the header.'
  19. hd._setMustUnderstand ('InteropTestHeader', 0)
  20. hd._setActor ('InteropTestHeader','http://schemas.xmlsoap.org/soap/actor/next')
  21. server = server._hd (hd)
  22. print server.echoInteger (test)
  23. ## /CODE
  24. This should succeed (provided the server has defined echoInteger), as it
  25. builds a valid header into this client with MustUnderstand set to 0
  26. and then sends the SOAP with this header.
  27. ## CODE
  28. import SOAPpy
  29. test = 42
  30. server = SOAPpy.SOAPProxy("http://localhost:8888")
  31. server = server._sa ("urn:soapinterop")
  32. #Header
  33. hd = SOAPpy.Header()
  34. hd.InteropTestHeader = 'This should fault,as you don\'t understand the header.'
  35. hd._setMustUnderstand ('InteropTestHeader', 1)
  36. hd._setActor ('InteropTestHeader','http://schemas.xmlsoap.org/soap/actor/next')
  37. server = server._hd (hd)
  38. print server.echoInteger (test)
  39. ## /CODE
  40. This should fail (even if the server has defined 'echoInteger'), as it
  41. builds a valid header into this client, but sets MustUnderstand to 1
  42. for a message that the server presumably won't understand before sending.
  43. SERVER EXAMPLES
  44. ---------------
  45. ## CODE
  46. import SOAPpy
  47. def echoInteger (inputInteger):
  48. return inputInteger
  49. server = SOAPpy.SOAPServer ( ('localhost', 8080) )
  50. server.registerFunction (echoInteger)
  51. server.serve_forever()
  52. ## /CODE
  53. This is a simple server designed to work with the first 2 clients above.
  54. ## CODE
  55. import SOAPpy
  56. def echoInteger (inputInteger, _SOAPContext):
  57. c = _SOAPContext
  58. print c.xmldata
  59. print c.header
  60. print c.body
  61. print c.connection.getpeername()
  62. print c.soapaction
  63. print c.httpheaders
  64. return inputInteger
  65. host = 'localhost'
  66. port = 8888
  67. server = SOAPpy.SOAPServer ( (host, port) )
  68. server.registerFunction (SOAPpy.MethodSig(echoInteger, keywords=0,context=1))
  69. server.serve_forever()
  70. ## /CODE
  71. This is a server which shows off the SOAPContext feature. This
  72. server gets a context from the client that has connected to it, and
  73. prints some of the pertinent aspects of that client before
  74. returning. This server should also work with the code for the two
  75. clients written above.
  76. $Id: UsingHeaders.txt,v 1.1 2005/02/18 15:36:12 warnes Exp $