Hi

Thanks for your reply.

On 1 December 2010 13:29, Dieter Maurer <[email protected]> wrote:
> Michael Wood wrote at 2010-12-1 09:16 +0200:
>>I'm pretty new to SOAP and soaplib.
>>
>>Is there a way to have a list of key, value pairs where the values
>>could be any primitive type, or possibly a structure and return that
>>from a SOAP service?
>
> A long time ago, I made something like this with
> ZSI (and Zope). While this has been a SOAP (based) service,
> it was not described by a WSDL but instead used dynamic typing
> (each value in the SOAP message used an "xsi:type" attribute to
> specify its type).
>
> I expect that you want a WSDL described service.
>
> In principle, WSDL (more precisely "XML-Schema" on which WSDL depends)
> supports so called "urtype"s, among others an "anyType" "urtype".
> This is however an advanced feature. Frameworks might have
> difficulties with it (I met e.g. difficulties with "PyXB", quickly
> fixed by its author).
>
> I do know the "soaplib" details -- and wether it can handle
> arbitrary types.

I see there is an Any serializer and also AnyAsDict, but I don't see
any mention of them in the examples.  Maybe this is what I'm looking
for?

I've just managed to do this:

>>> from soaplib.serializers.primitive import AnyAsDict
>>> from lxml import etree
>>> parent = etree.Element("parent")
>>> s = AnyAsDict()
>>> s.to_xml({"a": ["One"], "b": ["Two"], "c": [3]}, 'tns', parent)
>>> for element in parent.getchildren():
...     print etree.tostring(element)
...
<ns0:retval xmlns:ns0="tns"><a>One</a><c>3</c><b>Two</b></ns0:retval>
>>> print s.from_xml(parent.getchildren()[0])
{'a': ['One'],'c': ['3'],'b': ['Two']}
>>>

Does that look about right?

>  >So something like a Dict, where I can add to the
>>entries in the Dict over time without the WSDL changing.  I'm using
>>the 1.0 branch of soaplib.
>>
>>I'll need to consume this from a client written in C/C++.
>
> Then, this client, too, must be able to handle "xsi:type" attributes.
> Maybe, this is even a stronger restriction than on the Python side.

Yes, it's definitely more restrictive than the Python side.  I don't
know if it can handle xsi:type attributes.

>>If this is not possible, I'll just stick with a class with predefined
>>fields and use the ClassSerializer, but it would be nice if I could
>>avoid the WSDL changing and therefore having to update the client if I
>>add new fields to the class/dict/whatever.
>
> Maybe, other techniques would be more adequate for you
> (e.g. XML-RPC, JSON-RPC, ...)? They are "by nature" dynamic,
> not restricted by a static description.

Thanks for the suggestions.  I think I'm stuck with SOAP for the
moment, but perhaps something else will be better for a future
version.

Regards,
Michael

-- 
Michael Wood <[email protected]>
_______________________________________________
Soap mailing list
[email protected]
http://mail.python.org/mailman/listinfo/soap

Reply via email to