[Soap-Python] ComplexType Within ComplexTypes in Django ?

Fabian Rothfuchs fabian at rothfuchs.net
Thu Jul 31 17:31:50 CEST 2014


Hey there,

I got this solved by defining a sequence as ``_returns`` :
> 
>     @rpc(Unicode, _returns=(StatusComplexType, SubscriberComplexType), _out_variable_names=('status', 'result'))
>     def getSubscriberByID(self, subscriber_id):
>         """ Returns One Subscriber matching the given ID """
> 
>         status = StatusComplexType()
> 
>         try:
>             subscriber = Subscriber.objects.get(subscriber_id=subscriber_id)
>         except Subscriber.DoesNotExist:
>             status.code = 404
>             status.message = unicode(_(u'Subscriber with ID ``%(subscriber_id)s`` does not exist.' % {'subscriber_id': subscriber_id}))
>             return (status,)
> 
>         status.code = 200
>         status.message = 'OK'
> 
>         return (status, subscriber)

Cheers
Fabian



> On 31 Jul 2014, at 14:22, Fabian Rothfuchs <fabian at rothfuchs.net> wrote:
> 
> Update:
> 
> When doing this:
> 
> response.append_field('status', StatusComplexType)
> response.append_field('data', SubscriberComplexType)
> 
> then it *sometimes*  works as expected - and sometimes, ``response.status`` / ``response.data`` is ``NoneType``. This is very confusing to me.
> 
> Thank you!
> Fabian
> 
> 2014-07-31 14:12 GMT+02:00 Fabian Rothfuchs <fabian at rothfuchs.net>:
> Hey there, 
> 
> I'm just in the process of building a SOAP interface. While any SOAP interface may return different ComplexTypes, I want all of them to provide a ``status`` object as well. 
> 
> Given my (variable) Payload ComplexType's name is "Subscriber":
> 
> FooInterfaceResponse:
> > Status
> >> Code
> >> Message
> > PayLoad
> >> Subscriber
> >>> Name
> >>> Surname
> >>> .. 
> 
> My definition:
> 
> class SubscriberComplexType(DjangoComplexModel):
>     class Attributes(DjangoComplexModel.Attributes):
>         django_model = Subscriber
> 
> class StatusComplexType(ComplexModel):
>     code = UnsignedInteger16()
>     message = Unicode()
>     more_info = Unicode()
> 
> class SubscriberReturnComplexType(ComplexModel):
>     status = StatusComplexType()
>     data = SubscriberComplexType()
> 
> class SubscriberReadOnlyService(ServiceBase):
>     @rpc(Unicode, _returns=SubscriberReturnComplexType)
>     def getSubscriberByID(self, subscriber_id):
>         """ Returns One Subscriber matching the given ID """
>         response = SubscriberReturnComplexType()
>         try:
>             subscriber = Subscriber.objects.get(subscriber_id=subscriber_id)
>         except Subscriber.DoesNotExist:
>             response.status.code = 404
>             response.status.message = unicode(_(u'Subscriber with ID ``%(subscriber_id)s`` does not exist.' % {'subscriber_id': subscriber_id}))
>             return response
>         response.data = response.data.init_from(subscriber)
>         response.status.code = 200
>         response.status.message = 'OK'
>         return response
> 
> But this gives me an empty response:
> 
> <senv:Envelope xmlns:tns="devicementor" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">
>    <senv:Body>
>       <tns:getSubscriberByIDResponse>
>          <tns:getSubscriberByIDResult/>
>       </tns:getSubscriberByIDResponse>
>    </senv:Body>
> </senv:Envelope>
> 
> Any idea what I am missing?
> 
> Thank you! 
> Fabian
> 
> 
> 
> 
> 
> 
> -- 
> 
> 
> Fabian Rothfuchs
> Professional IT Services
> 
> Spilhofstraße 4a
> D-81927 München (Munich)
> Germany
> 
> C: +49 (0) 176 / 322 49 384 
> P: +49 (0) 89 / 54 89 27 14
> M: fabian at rothfuchs.net
> W: www.rothfuchs.net 
> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/soap/attachments/20140731/e70d467d/attachment-0001.html>


More information about the Soap mailing list