I wrote a webservice to create a new invoice in the database, but I am having problems to pass the line itens from a windows client to this WS. MY WS is:
namespace InvoicesTest
{
/// <summary>
/// Summary description for Invoices
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Invoices : System.Web.Services.WebService
{
[Serializable]
public struct InvoiceItem
{
public string Product {get; set;}
public string PartNumber {get; set;}
}
[WebMethod(Description = "Create Document Type")]
public string newDocType(string docTypeName, List<InvoiceItem> lstInvoiceItem)
{
for (int i = 0; i < lstInvoiceItem.Count; i++)
{
...
return "ok";
}
}
}
Until here is ok. My problem is to pass the values from a windows form to this WS. First I got an error that I should send an array instead List...
Now, I am getting an error like System.IndexOutOfRangeException: Index was outside the bounds of the array
private void button4_Click(object sender, EventArgs e)
{
InvoiceItem[] dt = new InvoiceItem[listView1.Items.Count];
int j = 0;
foreach (ListViewItem listItem in listView1.Items)
{
dt[j].Product = listItem.SubItems[0].Text;
dt[j].PartNumber = listItem.SubItems[1].Text;
j++;
}
textBox1.Text = InvoicesTest.newDocType("teste", dt.ToArray());
}
Even working with List<>, it doesnt work.
I appreciate any help...