[Soap-Python] List of objects
Minh Luu
minh_luu at toll.com.au
Mon Aug 30 23:53:33 CEST 2010
Thanks for the reply.
I tried to use the version 0.9.x but it doesn't seem to work
with twisted, so I am now using version 0.8.1. The problem
I have is that the client has already been written by a thirdparty,
and I need to write the server side to match the client request.
The *extact* incoming message is like this:
<?xml version="1.0" encoding="UTF-8"?>
<ns6:Envelope xmlns:ns8="http://abc.com/Types.xsd" xmlns:ns2="http://abc.com/Addressing.xsd"
xmlns:ns3="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns4="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ns5="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:ns6="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns7="http://abc.com/CarrierDelivery.xsd">
<ns6:Header>
....
</ns6:Header>
<ns6:Body>
<n7:DeliveryMsg>
<n7:Despatch>
<n7:contacts>
<n7:contact>
<n7:name>Allan</n7:name>
<n7:title>MR</n7:title>
</n7:contact>
<n7:contact>
<n7:name>Julie<n7:/name>
<n7:title>MS<n7:/title>
<n7:/contact>
<n7:/contacts>
</n7:Despatch>
</n7:DeliveryMsg>
</ns6:Body>
</ns6:Envelope>
My soap method is:
class SOAPService(SimpleWSGISoapApp):
@soapmethod(Despatch, _return=String)
def DeliveryMsg(self, Despatch):
...
return "message received"
The problem I have is there are multiple contact entries in contacts.
Using Array(Contact) doesn't work because the incoming message doesn't
have an array tag around the contact.
Can I use the Any class like, Contacts = Any, and handle the xml within
my app. If so, how can I get the xml value of the Contacts?
THANK AGAIN FOR YOUR HELP.
-----Original Message-----
From: soap-bounces+minhl=toll.com.au at python.org [mailto:soap-bounces+minhl=toll.com.au at python.org] On Behalf Of Burak Arslan
Sent: Tuesday, 31 August 2010 5:07 AM
To: soap at python.org
Subject: Re: [Soap-Python] List of objects
On 08/30/10 08:32, Minh Luu wrote:
> Hi,
>
> I am new to soaplib. I would like to setup a service that would accept the following XML
>
> <contacts>
> <contact>
> <name>Allan</name>
> <title>MR</title>
> </contact>
> <contact>
> <name>Julie</name>
> <title>MS</title>
> </contact>
> </contacts>
>
> I have try this but it didn't work. I get the error of 'NoneType object has no attribute from_xml
>
> class Contact(ClassSerializer):
> class types:
> name = String
> title = String
>
> class Contacts(ClassSerializer):
> class types:
> contact = Array(Contact)
>
>
what version of soaplib is it?
the sample xml does not contain a method call, nor namespace
qualifications. soaplib won't accept that *exact* message inside a soap
envelope. you need to define some methods.
here's what i'd do (with 0.9.x, minus imports)
class Contact(ClassSerializer):
name = String
title = String
class Contacts(ClassSerializer):
contact = Array(Contact)
class ServiceDefinition(soaplib.service.DefinitionBase):
@rpc(_returns=Array(Contact))
def get_contacts(self)
c1 = Contact()
c1.name = 'punk'
c1.title = 'ceo'
c2 = Contact()
c2.name = 'nerd'
c2.title = 'cto'
return [c1,c2]
look here for an example about what to do with that service:
http://github.com/arskom/soaplib/blob/master/examples/helloworld.py
hth
burak
_______________________________________________
Soap mailing list
Soap at python.org
http://mail.python.org/mailman/listinfo/soap
More information about the Soap
mailing list