Search code examples
c#xml-rpc

Passing array of XmlRpcStruct in XML-RPC throws error in C#


I am using XML_RPC v2.5.0 for .Net to make few calls to web service to send product data. All calls are working OK except one scenario. I am sending product data to the web service that is expected to be in the below format(Format is defined in PhP language) -

$order['products'][] = ['sku', 'quantity']

I am using the below code to pass this data -

XmlRpcStruct dic = new XmlRpcStruct();
DataTable dt1 = GetData();
XmlRpcStruct[] prod = new XmlRpcStruct[dt1.Rows.Count];
for (int i = 0; i < dt1.Rows.Count; i++)
{
   prod[i] = new XmlRpcStruct();
   prod[i].Add("sku", dt1.Rows[i][0].ToString());
   prod[i].Add("quantity", dt1.Rows[i][1].ToString());
}
dic.Add("products", prod);
object orderID = proxy.SubmitOrder(dic, custID, accessKey);

The above code works when there is only 1 row in the data table dt1 and I get the orderID successfully. However, if there are more than 1 records in the data table, I am getting an exception as -

A parameter is of, or contains an instance of, type CookComputing.XmlRpc.XmlRpcStruct which cannot be mapped to an XML-RPC type

I think I am missing something silly here. Please help and let me know what mistake I am doing here. Thanks in advance!


Solution

  • The code written above works OK. The issue with me was passing a null value to one of the other parameters when passing an array and hence the issue.