Reputation: 367
I'm trying to call an xml-rpc web service method that takes 1 parameter (an array of values) key and leads.
Key must be named 'key' and must have a value of type string. Leads is an xml document containing the leads data.This must be packaged as a binary object. This value must be named leads and must be of type base64.
Alright so the SINGLE parameter for this method call in python is:
r = proxy.leads({'key': key, 'leads': doc})
My first question is how can I do this in c#? The closest thing .net has to that is a dictionary object which won't work for this.
Secondly, how do I make the xml doc a binary object of type base64? Is that the same as converting a byte[] array to base64 string? Like this:
Convert.ToBase64String(byteArray)
Here is what the request should look like:
<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>leads</methodName>
<params>
<param>
<value>
<struct>
<member>
<name>key</name>
<value>
<string>XXXXXXXXXXX</string>
</value>
</member>
<member>
<name>leads</name>
<value>
<base64>PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPGxlYWRzPgogICA8bGVhZD4K
ICAgICAgPGlkPjM5OTk3PC9pZD4KICAgICAgPEZpcnN0TmFtZT5Cb2IgSmltPC9GaXJzdE5hbWU+
CiAgICAgIDxMYXN0TmFtZT5TbWl0aDwvTGFzdE5hbWU+CiAgICAgIDxBZGRyZXNzPjEyMzQgV2Vz
:
:
ICAgICA8UmVjZWl2ZUFkZGxJbmZvPlllczwvUmVjZWl2ZUFkZGxJbmZvPgogICAgICA8bG9wX3dj
X3N0YXR1cz5ObzwvbG9wX3djX3N0YXR1cz4KICAgPC9sZWFkPgo8L2xlYWRzPg==
</base64>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>
I'm completely stuck on this problem. Any help would be much appreciated.
Upvotes: 0
Views: 7603
Reputation: 100527
Check this out http://codinghints.blogspot.com/2010/03/xml-rpc-calls-with-c.html to see how one can manually call the service. There are probably libraries to do it in nice way...
How you specify parameters depends on what approach you find to construct the request. In case of manually constructing request (I'd recommend XDocument to build XML, not String.Format, but String.Format may be ok in very simple cases like your example) you would just put values into right places in boilerplate XML...
Yes byte array to base64 is Convert.ToBase64String(byteArray)
.
Something like following could be enough (but please try use proper ways to construct XML for non-one-time-use code):
String.Format("<?xml versi... <name>key</name><value><string>{0}</string>...",
key, Convert.ToBase64String(byteArray));
Upvotes: 1