如何将对象添加到 WSDL 服务 system.array

How to add object to WSDL service system.array

我目前正在使用具有保存发票方法的 WSDL。我已经能够修改现有发票,但还不知道如何保存新发票。由于数组大小是不可变的,我无法将对象添加到检索到的数组中。我应该如何保存新发票,有没有办法将它们添加到数组中? WSDL 没有另一种方法来保存单个发票。

Invoices.InvoiceOrder[] po = _service.GetInvoices(_params, invoiceReturnProperties, rowReturnProperties);

//test import of new po
Invoices.InvoiceOrder newInvoice = new Invoices.InvoiceOrder();

//specify individual properties that need to be set

newInvoice.OrderId = 28;
newInvoice.CustomerName = "James Bond";
newInvoice.CustomerId = 28;

po[po.Length] = newInvoice; //not sure how to accomplish this

//save invoices
_service.SaveInvoices(po);

为什么说数组是不可变的呢?倒数第二行是否抛出错误?

如果它实际上是不可变的,您可以使用 Array.Clone 复制现有数组并传递它。或者,如果服务只希望将 new/edited 发票传递给 SaveInvoices 操作(这对我来说更有意义),您可以这样做:

//save invoices
_service.SaveInvoices(new [] {p});

了解 Array.Clone 方法: https://msdn.microsoft.com/en-us/library/system.array.clone.aspx