Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print client.last_received().getChild("soap:Envelope").getChild("soap:Header")
- .getChild("ResponseHeader").getChild("resultCode").getText()
- from suds.plugin import MessagePlugin
- class HeaderPlugin(MessagePlugin):
- def __init__(self):
- self.document = None
- def parsed(self, context):
- self.document = context.reply
- def get_headers(self, method):
- method = method.method
- binding = method.binding.output
- rtypes = binding.headpart_types(method, False)
- envns = ('SOAP-ENV', 'http://schemas.xmlsoap.org/soap/envelope/')
- soapenv = self.document.getChild('Envelope', envns)
- soapheaders = soapenv.getChild('Header', envns)
- nodes = soapheaders.children
- if len(nodes):
- resolved = rtypes[0].resolve(nobuiltin=True)
- return binding.unmarshaller().process(nodes[0], resolved)
- return None
- from suds.client import Client
- hp = HeaderPlugin()
- client = Client(wsdl, plugins=[hp])
- response = client.service.LoremIpsum()
- headers = hp.get_headers(client.service.LoremIpsum)
- >>> headers
- (AuthenticationResponseHeader){
- sessionKey = "a631cd00-c6be-416f-9bd3-dbcd322e0848"
- validUntil = 2030-01-01 01:01:01.123456+01:00
- }
- >>> headers.validUntil
- datetime.datetime(2030, 1, 1, 1, 1, 1, 123456, tzinfo=<suds.sax.date.FixedOffsetTimezone object at 0x7f7347856be0>)
- class HeaderPlugin(MessagePlugin):
- def __init__(self):
- self.document = None
- def parsed(self, context):
- self.document = context.reply
- def get_headers(self, method):
- Result = {} #Soap Header list
- method = method.method
- binding = method.binding.output
- SHeaderElem = binding.headpart_types(method, False)
- envns = ('SOAP-ENV', 'http://schemas.xmlsoap.org/soap/envelope/')
- soapenv = self.document.getChild('Envelope', envns)
- soapheaders = soapenv.getChild('Header', envns)
- SHeaderNodes = soapheaders.children
- for Elem in SHeaderElem:
- for Node in SHeaderNodes:
- if(Node.name == Elem.name):
- ElemRes = Elem.resolve(nobuiltin=True)
- NodeRes = binding.unmarshaller().process(Node, ElemRes)
- Result[Elem.name] = NodeRes
- return Result
- #
- <soap-env:Envelope xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
- <soap-env:Header>
- <eb:MessageHeader eb:version="1.0" soap-env:mustUnderstand="1">
- <!-- -->
- </eb:MessageHeader>
- <wsse:Security>
- <!-- -->
- </wsse:Security>
- </soap-env:Header>
- <soap-env:Body>
- <!-- -->
- </soap-env:Body>
- </soap-env:Envelope>
- SoapHeadersResp = {'MessageHeader':MessageHeader, 'Security':SecurityObj}
Add Comment
Please, Sign In to add comment