how to omit tns from response and change tag name in spyne?
Question:
how do omit tns from my response and also change the tag name.?
my response is like this
<soap11env:Envelope >
<soap11env:Body>
<tns:FnSchedule_CityResponse>
<tns:FnSchedule_CityResult>
<tns:ErrorString></tns:ErrorString>
<tns:CityName>HYDERABAD</tns:CityName>
<tns:CityId>1</tns:CityId>
<tns:ErrId>0</tns:ErrId>
</tns:FnSchedule_CityResult>
</tns:FnSchedule_CityResponse>
</soap11env:Body>
</soap11env:Envelope>
I want to remove tns and change “soap11env” to “soap”.
Having these values is causing validation issues.
i referred this question on stack overflow, implemented it, but was not helpful.
Remove the namespace from Spyne response variables
Answers:
In order to change soap11env to soap just simply override the response using
application.interface.nsmap['soap'] = application.interface.nsmap['soap11env']
The ‘tns’ or target namespaces must not be change but there may arrive a few cases, One might need to change a name in order to completely test something.
To change the namespaces,
def on_method_return_string(ctx):
ctx.out_string[0] = ctx.out_string[0].replace(b'ns4', b'diffgr')
ctx.out_string[0] = ctx.out_string[0].replace(b'ns5', b'msdata')
YourModelClassName.event_manager.add_listener(‘method_return_string’,
on_method_return_string)
What I did here was, replace the namespace ns4 with diffgr and ns5 with msdata. ns4 and ns5 are sub name spaces that I had in the responses of some third party application. This solution I found in the mailing list maintained for spyne.
This answer did the trick but, is there a way to do it w/o on_method_return_string(ctx) as it is executing per response. In addition, it does string replace a few times. I would like to avoid it, if possible as it may create performance issues in my application.
how do omit tns from my response and also change the tag name.?
my response is like this
<soap11env:Envelope >
<soap11env:Body>
<tns:FnSchedule_CityResponse>
<tns:FnSchedule_CityResult>
<tns:ErrorString></tns:ErrorString>
<tns:CityName>HYDERABAD</tns:CityName>
<tns:CityId>1</tns:CityId>
<tns:ErrId>0</tns:ErrId>
</tns:FnSchedule_CityResult>
</tns:FnSchedule_CityResponse>
</soap11env:Body>
</soap11env:Envelope>
I want to remove tns and change “soap11env” to “soap”.
Having these values is causing validation issues.
i referred this question on stack overflow, implemented it, but was not helpful.
Remove the namespace from Spyne response variables
In order to change soap11env to soap just simply override the response using
application.interface.nsmap['soap'] = application.interface.nsmap['soap11env']
The ‘tns’ or target namespaces must not be change but there may arrive a few cases, One might need to change a name in order to completely test something.
To change the namespaces,
def on_method_return_string(ctx):
ctx.out_string[0] = ctx.out_string[0].replace(b'ns4', b'diffgr')
ctx.out_string[0] = ctx.out_string[0].replace(b'ns5', b'msdata')
YourModelClassName.event_manager.add_listener(‘method_return_string’,
on_method_return_string)
What I did here was, replace the namespace ns4 with diffgr and ns5 with msdata. ns4 and ns5 are sub name spaces that I had in the responses of some third party application. This solution I found in the mailing list maintained for spyne.
This answer did the trick but, is there a way to do it w/o on_method_return_string(ctx) as it is executing per response. In addition, it does string replace a few times. I would like to avoid it, if possible as it may create performance issues in my application.