Fetching data from dynamics ax 2009 using Ax webservices and C#

纵饮孤独 提交于 2019-12-08 08:36:27

I found out how to do it..here is the solution as to how to Consume AIF webservices.here is the code.Please refer the following article http://msdn.microsoft.com/en-us/library/cc652581.aspx

        customerService.CustomerServiceClient sc = new ConsumingAxWebService.customerService.CustomerServiceClient();

         AxdCustomer axdCustomer;

        QueryCriteria queryCriteria;
        CriteriaElement[] criteriaElements;
        IEnumerator enumerator;
        int iCountLoops1 = 0;
        AxdEntity_CustTable cust;


        criteriaElements = new CriteriaElement[1];
        criteriaElements[0] = new CriteriaElement();

        criteriaElements[0].DataSourceName = "CustTable";
        criteriaElements[0].FieldName = "AccountNum";
        criteriaElements[0].Operator = Operator.Range;
        criteriaElements[0].Value1 = "1101";
        criteriaElements[0].Value2 = "1102";


        queryCriteria = new QueryCriteria();
        queryCriteria.CriteriaElement = criteriaElements;
        axdCustomer = sc.find(queryCriteria);

        enumerator = axdCustomer.CustTable.GetEnumerator();

        while (enumerator.MoveNext())
        {
            ++iCountLoops1;
            cust = (AxdEntity_CustTable)enumerator.Current;
            Response.Write(cust.AccountNum + "\n");
        }
Pedro

As dates and I can move decimal to the web service in Ax, the name of the service I am using is CustFreeTextInvoice ..

Passing string data no problem but with date and decimal data itself.

code attached ...

private void btnIngresar_Click(object sender, EventArgs e)
    {
        FreeTextInvoiceServiceClient service = new FreeTextInvoiceServiceClient();

        if (null == service)
        {
            throw new Exception("Cannot instantiate service.");
        }

        AxdFreeTextInvoice FreeTextInvoice = new AxdFreeTextInvoice();

        //Record
        AxdEntity_CustInvoiceTable CustInvoiceTable = new AxdEntity_CustInvoiceTable();
        CustInvoiceTable.InvoiceId = "100";
        CustInvoiceTable.Name = txtName.Text;
        CustInvoiceTable.OneTimeCustomer = 0;
        CustInvoiceTable.OrderAccount = txtOrderAccount.Text;
        //CustInvoiceTable.DocumentDate = DateTime.Now;
        //CustInvoiceTable.DueDate = Convert.ToDateTime("20/12/2011");
        CustInvoiceTable.InvoiceDate = Convert.ToDateTime("20/11/2011");

        CustInvoiceTable.CustInvoiceLine = new AxdEntity_CustInvoiceLine[2];

        CustInvoiceTable.CustInvoiceLine[0] = new AxdEntity_CustInvoiceLine();
        CustInvoiceTable.CustInvoiceLine[0].Description = "Primer registro";
        CustInvoiceTable.CustInvoiceLine[0].LedgerAccount = "610208";
        CustInvoiceTable.CustInvoiceLine[0].TaxGroup = "IVAVTAS12";
        CustInvoiceTable.CustInvoiceLine[0].TaxItemGroup = "all";
        CustInvoiceTable.CustInvoiceLine[0].AmountCur = 1000;

        CustInvoiceTable.CustInvoiceLine[1] = new AxdEntity_CustInvoiceLine();
        CustInvoiceTable.CustInvoiceLine[1].Description = "segundo registro";
        CustInvoiceTable.CustInvoiceLine[1].LedgerAccount = "610208";
        CustInvoiceTable.CustInvoiceLine[1].TaxGroup = "IVAVTAS12";
        CustInvoiceTable.CustInvoiceLine[1].TaxItemGroup = "all";
        CustInvoiceTable.CustInvoiceLine[1].AmountCur = 90;

        FreeTextInvoice.CustInvoiceTable = new AxdEntity_CustInvoiceTable[1] { CustInvoiceTable };

       try
        {
            testws.FTIS.EntityKey[] returned = service.create(FreeTextInvoice);
            testws.FTIS.EntityKey returnedValues = (testws.FTIS.EntityKey)returned.GetValue(0);
            Console.WriteLine("Valor retornado: " + returnedValues.KeyData[0].Value);
            Console.ReadLine();

        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.ToString());
            Console.ReadLine();
        }
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!