[英]XMLRPC.Net how do you pass in an associated array?
我正在使用開源庫xmlrpc.net,並試圖調用具有輸入參數(是關聯數組)的服務。
待命文檔(我正在嘗試與名為Magento的phpsite集成,由於拋出的錯誤,我知道它正在使用Zend xmlrpc庫。)
方法名稱:sales_order_shipment.create為訂單創建新貨件
返回:字符串-裝運增量編號
參數:
字符串orderIncrementId-訂單增量ID數組itemsQty-要作為關聯數組裝運的項目數量(order_item_id⇒qty)字符串注釋-裝運注釋(可選)布爾電子郵件-發送電子郵件標志(可選)boolean includeComment-在電子郵件標志中包含注釋(可選的)
因此,在.Net中,我已經能夠完成以下工作
proxy.Create(sessionId, "sales_order_shipment.create", new object[] { 100000010, new object[] { }, "Shipment Created", true, true });
但是我似乎無法弄清楚應該為itemsQty傳遞什么.Net類型。 new object [] {}有效,但我需要能夠傳遞已裝運的物品,而不僅僅是創建其中包含0件物品的物品。 可以使用哪種.Net類型,將使用xmlrpc.net映射到關聯數組
在沒有看到應該生成的XML-RPC請求的情況下,規范對我來說並不明確,但是如何像這樣使用XmlRpcStruct:
XmlRpcStruct items = new XmlRpcStruct();
items["orderid1"] = 1;
items["orderid2"] = 2;
(假設訂單ID是一個字符串)
我一直在使用相關方法sales_order_invoice.create並遇到與您相同的問題。 我只是發現,無論出於什么原因,如果我在發票上添加注釋,我都必須在傳遞給服務器的參數數組中插入一個額外的元素。
我正在運行Magento EE版本。 1.11.0.2使用C#和XML-RPC.Net v2庫(CookComputing.XmlRpcV2.dll)將數據與Magento集成。
我偶然發現此空白決議,注意到空發票的注釋為“ 0”,這是我為“ Send invoice on email (optional)
字段提供的值,並決定嘗試在注釋之前插入一個空元素,然后評論出現了,但物品仍未開具發票。 然后,我將空元素移到了項目列表之前,一切正常。 我檢查了API的代碼/app/code/core/Mage/Sales/Model/Order/Invoice/Api.php,但找不到這種情況的位置或原因。 我唯一的猜測是,它與解析XML-RPC請求的庫沒有任何關系,因為此調用在其他參數的中間有一個數組。
在嘗試診斷這一點時,我使用了XML-RPC記錄器
logger = new RequestResponseLogger();
logger.Directory = "C:\Temp\";
magentoProxy.AttachLogger(logger);
logger.UnsubscribeFrom(magentoProxy);
然后,每當我想查看請求響應在呼叫中時,我只需將這些呼叫放在XML-RPC呼叫之前和之后
logger.SubscribeTo(magentoProxy);
// call to Magento that I want to see the XML for request and responses to
logger.UnsubscribeFrom(magentoProxy);
我沒有發現發送給Magento進行API調用的XML的任何問題。 我唯一想到的另一件事是啟動帶有調試器的magento,並觀察當Api.php文件或堆棧中的create方法混亂時,發生什么情況,但是我沒有這么做。當時我還沒有設置我的開發環境來進行Magento代碼的主動調試,並且現在不想花時間去研究這一方面。
我要做的工作是在調用之后創建一些代碼,以創建可再次從Magento中拉出order_info的發票,並檢查訂單上的所有項目是否已開票,如果沒有,則拋出一個丑陋的結果錯誤。 我認為,如果在某個時候該“錯誤”或引起這種情況的任何原因得到修復或更改,我至少會知道它是否影響從此調用中獲得發票的訂單商品。
// Get the order items that need to be invoiced
// this.orderInfo is the XmlRpcStruct returned from a sales_order.info call
XmlRpcStruct[] orderItems = this.orderInfo.Contains("items") ? (XmlRpcStruct[]) this.orderInfo["items"] : new XmlRpcStruct[] { };
XmlRpcStruct orderItemsToInvoice = new XmlRpcStruct();
Int32 orderItemId;
Int32 qtyOrdered;
Int32 qtyInvoiced;
Int32 qtyToInvoice;
foreach (XmlRpcStruct item in orderItems)
{
orderItemId = item.Contains("item_id") ? Convert.ToInt32(item["item_id"]) : 0;
qtyOrdered = item.Contains("qty_ordered") ? Convert.ToInt32(Convert.ToDecimal(item["qty_ordered"])) : 0;
qtyInvoiced = item.Contains("qty_invoiced") ? Convert.ToInt32(Convert.ToDecimal(item["qty_invoiced"])) : 0;
qtyToInvoice = qtyOrdered - qtyInvoiced;
orderItemsToInvoice[Convert.ToString(orderItemId)] = Convert.ToString(qtyToInvoice);
}
// Invoice This Order with a comment
String newInvoiceId = magentoProxy.salesOrderInvoiceCreate(sessionId: sessionId, arguments: new Object[] {
this.MageIncrementId, // Order increment ID
"", // this should not need to be here, but for some reason if I want to include a comment
// on the invoice I have to thave this extra empty element before the array of order items
// if no comment is included on the invoice this extra element is not needed, rather weird, I can not explain it.
orderItemsToInvoice, // array itemsQty Array of orderItemIdQty (quantity of items to invoice)
"Automatically invoiced prior to CounterPoint import." // Invoice Comment (optional)
//"0", // Send invoice on email (optional) defaults to false
//"0" // Include comments in email (optional) defaults to false
});
// Invoice This Order without a comment
String newInvoiceId = magentoProxy.salesOrderInvoiceCreate(sessionId: sessionId, arguments: new Object[] {
this.MageIncrementId, // Order increment ID
orderItemsToInvoice // array itemsQty Array of orderItemIdQty (quantity of items to invoice)
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.