python - Adding xsi:type and envelope namespace when using SUDS -
i need interact soap service , having lot of trouble doing so; appreciate pointers on this. original error message was:
org.apache.axis2.databinding.adbexception: type element type has not been given
after research, turns out disagreement between suds , server has how deal with
type="xsd:anytype"
on element in question.
i've confirmed using soapui , after advice problem can fixed taking these steps:
- adding xsi:type="xsd:string" each element causes problems
- adding xmlns:xsd="http://www.w3.org/2001/xmlschema" soap envelope
so, suds this:
<soap-env:envelope ... xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <ns3:body> <ns0:method> <parameter> <values> <table> <key>email_address</key> <value>example@example.org</value> </table> </values> </parameter> </ns0:method>
it should instead produce this:
<soap-env:envelope xmlns:xsd="http://www.w3.org/2001/xmlschema" ... xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <ns3:body> <ns0:method> ... <parameter> <values> <table> <key xsi:type="xsd:string">email_address</key> <value xsi:type="xsd:string">example@example.org</value> </table> </values> </parameter> </ns0:method>
is there correct way this? i've seen suggestions of using importdoctor or messageplugins, haven't grokked how achieve desired effect.
the solution found use messageplugin manually fix xml before sending. i'd hoped there more elegant, @ least works:
class soapfixer(messageplugin): def marshalled(self, context): # alter envelope xsd namespace allowed context.envelope.nsprefixes['xsd'] = 'http://www.w3.org/2001/xmlschema' # go through every node in document , apply fix function patch incompatible xml. context.envelope.walk(self.fix_any_type_string) def fix_any_type_string(self, element): """used filter function walk in order fix errors. if element has name, give xsi:type=xsd:string. note nsprefix xsd must added in make work.""" # fix elements have these names fix_names = ['elementnametofix', 'anotherelementname'] if element.name in fix_names: element.attributes.append(attribute('xsi:type', 'xsd:string'))
Comments
Post a Comment