API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

Speed problem

+1
Hello Experts,

I have developed a .NET application which creates invoices in e-conomics via API.

In my approach, first I create all invoices in local sql database.  It takes only 5 minutes to create all the invoices.

I have processed  2282 headers and 51677 lines in total. But if I want to upload these pre-created invoices to e-conomics, it takes about 6 hours.

I think it is a bit crazy.  There should be a better way of doing this.

I am using CreateFromArray function to create lines at once. In the beginning,  I was sending 600 lines at once and it was fast enough for me ( may be 1 -2 hours for all).

But later, I have received timeout exceptions after  1 hour. The timeout value is 20 minutes. Then I decreased it to 50 lines maximum per call.

This time,  I don't get any timeout exception but it is really slow.  Do you have a suggestion to increase the speed ?

Here is my snippets :

List<CurrentInvoiceLineData> invoiceLines = new List<CurrentInvoiceLineData>();

  EconomicWebServiceSoapClient cli  = getEconomis();

  CurrentInvoiceHandle inv = null;

  foreach (DataRow rowHeader in HeaderTable.Rows)
  {

      inv = getCurrentInvoiceWeb(cli, rowHeader.Row);

      foreach (DataRow row in dataTable.Rows)
      {
          if (row["HeaderId"] != rowHeader["Id"])
              continue;

          CurrentInvoiceLineData invoice = new CurrentInvoiceLineData();
          invoice.InvoiceHandle = inv;
          invoiceLines.Add(invoice);

          if (!rowline.Row.IsNull("Description"))
              invoice.Description = (string)rowline["Description"];

          if (!rowline.Row.IsNull("Quantity"))
              invoice.Quantity = (decimal)rowline["Quantity"];

          if (!rowline.Row.IsNull("UnitNetPrice"))
              invoice.UnitNetPrice = (decimal)rowline["UnitNetPrice"];

          if (!rowline.Row.IsNull("DiscountAsPercent"))
              invoice.DiscountAsPercent = (decimal)rowline["DiscountAsPercent"];

          if (invoiceLines.Count > 50)
          {

              cli.CurrentInvoiceLine_CreateFromDataArray(invoiceLines.ToArray());

              invoiceLines.Clear();
          }
      }
  }

      public CurrentInvoiceHandle getCurrentInvoiceWeb(EconomicWebServiceSoapClient ecoWeb, DataRow header)
        {
                DebtorHandle debitor = getDebitorWeb(ecoWeb, (int)header["Company"]);
                CurrentInvoiceHandle[] invoices = ecoWeb.Debtor_GetCurrentInvoices(debitor);

                if (invoices.Count() > 0)
                {
                    return invoices[0];
                }
                else
                {
                    CurrentInvoiceHandle inv = default(CurrentInvoiceHandle);
                    inv = ecoWeb.CurrentInvoice_Create(debitor);
                    ecoWeb.CurrentInvoice_SetHeading(inv, header["Heading"].ToString());

                    if (!header.IsNull("TextLine1"))
                    {
                        ecoWeb.CurrentInvoice_SetTextLine1(inv, header["TextLine1"].ToString());
                    }

                    if (!header.IsNull("TextLine2"))
                    {
                        ecoWeb.CurrentInvoice_SetTextLine2(inv, header["TextLine2"].ToString());
                    }
                }
        }

public economicServiceWeb.DebtorHandle getDebitorWeb(economicServiceWeb.EconomicWebServiceSoapClient ecoWeb, int company)
        {
            DataRow account = GetCompany(company);

            bool newDeb = false;
            economicServiceWeb.DebtorData deb = null;
            economicServiceWeb.DebtorHandle findDeb = ecoWeb.Debtor_FindByNumber(account["AccountNumber"].ToString());

            if ((findDeb != null))
            {
                deb = ecoWeb.Debtor_GetData(findDeb);
            }
            if (deb == null)
            {
                newDeb = true;
                economicServiceWeb.DebtorGroupHandle debGrp = ecoWeb.DebtorGroup_FindByNumber(1);
                //indenlandsk
                deb = new economicServiceWeb.DebtorData();
                deb.Number = account["AccountNumber"].ToString();
                deb.DebtorGroupHandle = debGrp;

                if (!account.IsNull("NoVATEU") && (bool)account["NoVATEU"])
                {
                    deb.VatZone = economicServiceWeb.VatZone.EU;
                }
                else
                {
                    deb.VatZone = economicServiceWeb.VatZone.HomeCountry;
                }

                deb.IsAccessible = true;
                economicServiceWeb.CurrencyHandle cur = ecoWeb.Currency_FindByCode("DKK");
                deb.CurrencyHandle = cur;
                economicServiceWeb.TermOfPaymentHandle[] tpayment = ecoWeb.TermOfPayment_FindByName("Netto 14 dage");
                deb.TermOfPaymentHandle = tpayment[0];
                economicServiceWeb.TemplateCollectionHandle[] layout = ecoWeb.TemplateCollection_FindByName("DK. std. uden F1");
                deb.LayoutHandle = layout[0];
            }

            bool bisDataUpdated = false;

            if (!isEqual(deb.Name, account["Name"].ToString()))
            {
                bisDataUpdated = true;
                deb.Name = account["Name"].ToString();
            }

            string address = Helper.GetText(account, "Street") + " " + Helper.GetText(account, "HouseNumber");

            if (!isEqual(deb.Address, address))
            {
                bisDataUpdated = true;
                deb.Address = address;
            }

            if (!isEqual(deb.City, Helper.GetText(account, "DistrictName")))
            {
                bisDataUpdated = true;
                deb.City = Helper.GetText(account, "DistrictName");
            }

            if (!isEqual(deb.Country, Helper.GetText(account, "Country")))
            {
                bisDataUpdated = true;
                deb.Country = Helper.GetText(account, "Country");
            }

            if (!isEqual(deb.Email, Helper.GetText(account, "InvoiceEmail")))
            {
                bisDataUpdated = true;
                deb.Email = Helper.GetText(account, "InvoiceEmail");
            }

            economicServiceWeb.DebtorHandle debitor = default(economicServiceWeb.DebtorHandle);
            if (newDeb)
            {
                debitor = ecoWeb.Debtor_CreateFromData(deb);
                ecoWeb.DebtorContact_Create(debitor, account["ContactPerson"].ToString());
            }
            else if (bisDataUpdated)
            {
                debitor = ecoWeb.Debtor_UpdateFromData(deb);
            }
            else
                return deb.Handle;

            return debitor;
        }
created Dec 3, 2013 by ibrahimyet
0% Accept Rate
Q 1 A 0 C 0

Network

Find all the documentation and resources you need to build great apps.
Go to Developer site

Newsletter

Get the latest news and important info from the e-conomic developer world.
Sign up now

Visma e-conomic A/S
...