Using Headers ============= SOAPpy has a Header class to hold data for the header of a SOAP message. Each Header instance has methods to set/get the MustUnderstand attribute, and methods to set/get the Actor attribute. SOAPpy also has a SOAPContext class so that each server method can be implemented in such a way that it gets the context of the connecting client. This includes both common SOAP information and connection information (see below for an example). CLIENT EXAMPLES --------------- ## CODE import SOAPpy test = 42 server = SOAPpy.SOAPProxy("http://localhost:8888") server = server._sa ("urn:soapinterop") hd = SOAPpy.Header() hd.InteropTestHeader ='This should fault, as you don\'t understand the header.' hd._setMustUnderstand ('InteropTestHeader', 0) hd._setActor ('InteropTestHeader','http://schemas.xmlsoap.org/soap/actor/next') server = server._hd (hd) print server.echoInteger (test) ## /CODE This should succeed (provided the server has defined echoInteger), as it builds a valid header into this client with MustUnderstand set to 0 and then sends the SOAP with this header. ## CODE import SOAPpy test = 42 server = SOAPpy.SOAPProxy("http://localhost:8888") server = server._sa ("urn:soapinterop") #Header hd = SOAPpy.Header() hd.InteropTestHeader = 'This should fault,as you don\'t understand the header.' hd._setMustUnderstand ('InteropTestHeader', 1) hd._setActor ('InteropTestHeader','http://schemas.xmlsoap.org/soap/actor/next') server = server._hd (hd) print server.echoInteger (test) ## /CODE This should fail (even if the server has defined 'echoInteger'), as it builds a valid header into this client, but sets MustUnderstand to 1 for a message that the server presumably won't understand before sending. SERVER EXAMPLES --------------- ## CODE import SOAPpy def echoInteger (inputInteger): return inputInteger server = SOAPpy.SOAPServer ( ('localhost', 8080) ) server.registerFunction (echoInteger) server.serve_forever() ## /CODE This is a simple server designed to work with the first 2 clients above. ## CODE import SOAPpy def echoInteger (inputInteger, _SOAPContext): c = _SOAPContext print c.xmldata print c.header print c.body print c.connection.getpeername() print c.soapaction print c.httpheaders return inputInteger host = 'localhost' port = 8888 server = SOAPpy.SOAPServer ( (host, port) ) server.registerFunction (SOAPpy.MethodSig(echoInteger, keywords=0,context=1)) server.serve_forever() ## /CODE This is a server which shows off the SOAPContext feature. This server gets a context from the client that has connected to it, and prints some of the pertinent aspects of that client before returning. This server should also work with the code for the two clients written above. $Id: UsingHeaders.txt,v 1.1 2005/02/18 15:36:12 warnes Exp $