Varios ejemplos C# .net para conectar con AX 4.0 utilizando Bussines conector

Filed under:.NET,4.0,Uncategorized,axapta,desarrollo,dynamics — posted by admin on June 24, 2010 @ 1:20 am

UAN

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx;
            DynAx =3D new =
Microsoft.Dynamics.BusinessConnectorNet.Axapta();
            // Test the connection to the .NET Business Connector=20
            // by using the proxy user.
            System.Net.NetworkCredential nc =3D new =
            System.Net.NetworkCredential("proxyBCAX", "********");
            try
            {
                DynAx.LogonAs("proxyBCAX", "", nc, "", "", "", =
                   "C:\\Documents and Settings\\1314\\Escritorio\\BC.AXC");
                //DynAx.LogonAs(Environment.UserName, "", null, "", "", =
                 "", "C:\\Documents and Settings\\1314\\Escritorio\\BC.AXC");
                Console.WriteLine( "Success Login OK");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
    }
}

CHU
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                label1.Text = "";

                Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new
                    Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                Microsoft.Dynamics.BusinessConnectorNet.AxaptaRecord DynRec;

                // Authenticate the user and establish a session.
                DynAx.Logon(Company.Text, null, AOS.Text, Configuration.Text);
                if (DynAx != null)
                {
                    label1.Text = ("Login OK");
                }

                // Define the record as the AddressState table.
                DynRec = DynAx.CreateAxaptaRecord("AddressState");

                // Define the query that will run on the AddressState records.
                // This will return all the data in the AddressState table with
                // the cursor positioned at the first record in the table.
                DynRec.ExecuteStmt("select * from %1");

                // Check if the query returned any data.
                if (DynRec.Found)
                {
                    // Display the record on the form that was retrieved from the query.
                    textBox1.Text = (string)DynRec.get_Field("Name");

                }
            }
            catch (Exception ex)
            {
                textBox1.Text = (ex.ToString());
                textBox1.Text += (ex.Message);
                label1.Text = ("Login Filed");
            }
        }
    }
}
ZRI
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

                label1.Text = "";

                Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new
                    Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                Microsoft.Dynamics.BusinessConnectorNet.AxaptaRecord DynRec;

            // Authenticate the user and establish a session.
                System.Net.NetworkCredential nc = new System.Net.NetworkCredential(USER.Text, PASS.Text);
            try
            {
                //"C:\\Documents and Settings\\1314\\Escritorio\\BC.AXC"
                DynAx.LogonAs(AXUser.Text, Domain.Text, nc, Company.Text, null, AOS.Text, Configuration.Text);

                if (DynAx != null)
                {
                    label1.Text = ("Login OK");
                }

                // Define the record as the AddressState table.
                DynRec = DynAx.CreateAxaptaRecord("AddressState");

                // Define the query that will run on the AddressState records.
                // This will return all the data in the AddressState table with
                // the cursor positioned at the first record in the table.
                DynRec.ExecuteStmt("select * from %1");

                // Check if the query returned any data.
                if (DynRec.Found)
                {
                    // Display the record on the form that was retrieved from the query.
                    textBox1.Text = (string)DynRec.get_Field("Name");

                }
                //DynAx.Logoff();
            }
            catch (Exception ex)
            {
                textBox1.Text = (ex.ToString());
                textBox1.Text += (ex.Message);
                label1.Text = ("Login Filed");
            }
        }
    }
}


image: detail of installation by Bronwyn Lace