tags:

views:

102

answers:

2

Hi.

I need to consume a webservice over XML-RPC. The webservice is written in Python, and one of the arguments is a Python list.

I'm using XML-RPC.NET to invoke all the methods and it works fine, except for those that require a Python list argument.

What would be the corresponding structure in C# which, if I pass as the argument, would be construed by the web service as a Python list? I've tried Python-style code in a string. I've also tried string arrays.

Any example would be really helpful.

Thanks, V

A: 

What you need to obtain in the underlying XML is an <array> tag, e.g.

<array>
   <data>
      <value><i4>12</i4></value>
      <value><string>Egypt</string></value>
      <value><boolean>0</boolean></value>
      <value><i4>-31</i4></value>
   </data>
</array>

for Python list

[12, 'Egypt', False, -31]

How you get XML-RPC.NET to emit an <array> tag with a heterogenous "array", I'm not sure. Do you have a way to visualize the XML that's getting emitted for certain C# input constructs/data structures...?

Alex Martelli
[12, 'Egypt', False, -31]
hughdbrown
@hughdbrown, tx for the spotting, edited to fix my typo.
Alex Martelli
Thanks guys. I used an array of objects as suggested by Christopher, and then tried mapping the Python list to the XML structure you've suggested. It worked. I had a complicated nested list so it took a while though. Also, I was able to see visualize the XML being generated by using the Tracer that comes with XML-RPC.NET at: http://xml-rpc.net/faq/xmlrpcnetfaq.html#5.1Thanks all!
Varun
Can I not mark two answers as the accepted answers? Used a combination of both so would ideally like to mark them both.
Varun
@Varun, you can only pick one as "accepted", and I think you picked the right one since Christopher's concise answer goes to the heart of the matter. Once your reputation's high enough to upvote, you can always come back and upvote both answers as well, if you found both of them good as you say!-)
Alex Martelli
+1  A: 

You need to use arrays of System.Object[]. See http://www.xml-rpc.net/faq/xmlrpcnetfaq.html#1.12 These are generally equivalent to Python lists.

Christopher
Thanks Christopher. An array of objects nested properly did in fact work to simulate a Python list.
Varun