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!
move this line of code
`dic.Add("products", prod);`
to the last line within your loop to make it work b/c it currently adds only single item to your dictionary.
The other mistake what I think the 'dic' and 'prod' object was not a List.
your code suppose to be:
`List<XmlRpcStruct> dic = new List<XmlRpcStruct>();
for (int i = 0; i < dt1.Rows.Count; i++)
{
List<XmlRpcStruct> prod = new List<XmlRpcStruct>();
prod.Add("sku", dt1.Rows[i][0].ToString());
prod.Add("quantity", dt1.Rows[i][1].ToString());
dic.Add("products", prod); //this line might be a culprit
}
object orderID = proxy.SubmitOrder(dic, custID, accessKey);`
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.