Reputation: 15
Im using Spyne & I try to add xsi:type="xsd:string" to my AnyDict result in response .
Now i have this one:
<soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://localhost/nusoap">
<soap11env:Body>
<tns:ERespons>
<tns:EResponsRecord>
<state>failed</state>
<err_msg>Nastala chyba</err_msg>
</tns:EResponsRecord>
</tns:ERespons>
</soap11env:Body>
</soap11env:Envelope>
But i need to get :
<soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://localhost/nusoap">
<soap11env:Body>
<tns:ERespons>
<tns:EResponsRecord>
<state xsi:type="xsd:string">failed</state>
<err_msg xsi:type="xsd:string">Nastala chyba</err_msg>
</tns:EResponsRecord>
</tns:ERespons>
</soap11env:Body>
</soap11env:Envelope>
My Service:
class AddEntryEC(ServiceBase):
EntryObject.__namespace__ = 'Entry.soap'
__out_header__ = EntryObject
@rpc(
AnyDict,
_out_message_name = 'ERespons',
_out_variable_name = 'EResponsRecord',
_returns=AnyDict
)
def AddEntry(ctx, data):
data = get_object_as_dict(data)
try :
ctx.app.db_tool.set_args(data)
res = ctx.app.db_tool.insert_data()
return res
except Exception as e:
logging.exception(e)
return {'state' : 'failed',
'err_msg' : 'Nastala chyba'}
My app declaration :
application = MyApplication([AddEntryEC], 'http://localhost/nusoap', in_protocol=Soap11(validator='soft'), out_protocol=Soap11())
Do u have some idea to help me with solution ?
Upvotes: 0
Views: 144
Reputation: 15
Thanks @Burak 🙂, my code now:
@rpc(
AnyDict,
_out_message_name = 'ERespons',
_returns=AnyXml
)
def AddEntry(ctx, data):
data = get_object_as_dict(data)
qname = etree.QName("http://www.w3.org/2001/XMLSchema-instance", "type")
root = etree.Element('EResponsRecord')
s = etree.SubElement(root, 'state')
s.attrib[qname] = 'string'
e = etree.SubElement(root, 'err_msg')
e.attrib[qname] = 'string'
try:
ctx.app.db_tool.set_args(data)
res = ctx.app.db_tool.insert_data()
s.text = res['state']
e.text = res['err_msg']
except Exception as e:
logging.exception(e)
s.text = 'failed'
e.text = 'Nastala chyba'
return root
Upvotes: 0
Reputation: 8001
AnyDict
can't handle this use case -- it simply doesn't have any means to store the additional metadata. You must set your return type as AnyXml
and return an Element
object with any desired attributes.
Upvotes: 0