我通过Visual Studio 2012 RC和C#使用SOAP来使用Magento API。我通过添加指向 SOAP WSDL 文件的服务引用来做到这一点。
现在,我在获取销售订单实体的送货地址时遇到困难。以下是我检索这些实体的方法。
var f = new filters();
f.filter = new associativeEntity[] {
new associativeEntity {
key ="status",
value ="processing"
}
};
var entities = mservice.salesOrderList(mlogin, f);
这很好用,但是当我遍历它们并显示它们的一些信息时,我偶然发现了一些奇怪的东西。
foreach (var entity in entities)
{
//the following line crashes for some strange reason.
//the error is SoapHeaderException: Address not exists.
var info = mservice.customerAddressInfo(mlogin, int.Parse(entity.shipping_address_id));
Debug.WriteLine(info.firstname);
}
送货地址不0
,确实已设置为正确的数字(是的,由于某种奇怪的原因,它是一个字符串,尽管它总是代表一个数字)。
我在这里做错了什么?
地址
存储在salesOrderAddressEntity
中,该位于salesOrderEntity
内。
var magento = new MagentoService();
var session = magento.login("LOGIN", "APIKEY");
var order = magento.salesOrderInfo(session, "100029631");
var address = order.shipping_address;
Console.WriteLine(address.firstname + " " + address.lastname);
Console.WriteLine(address.street);
Console.WriteLine(address.postcode + " " + address.city);