Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Consume AX Web service in Console App

(0) ShareShare
ReportReport
Posted on by 20

Hello All, 

I am new to dynamics AX and we have to create a contact person in AX using console application.

We created a new web service in AX and we have the WSDL for that 

Can some one provide is with an example of how to create a proper contact in dynamics AX using the AIF web service.

Regards,

Abhi

  • Martin Dráb Profile Picture
    231,777 Most Valuable Professional on at
    RE: Consume AX Web service in Console App

    If I open the link I gave you and search for "contact person", I can find the service. Please try these steps by youself. If you don't know how to find text on a web site, consult documentation of your web browser. I'm using Firefox and all I need to do is pressing Ctrl+F and typing the text to search.

    I'm sorry, but saying mere "The below code is generating errors" isn't sufficient. Are you still talking about the single error "Could not connect to ...", or do you mean other errors? If other, please explain whether they're compilation errors or runtime errors, where exactly they occur and what the error messages are.

    You can read F&O documentation to learn more about AIF and services, such as what types are available.

  • Abhi R Profile Picture
    20 on at
    RE: Consume AX Web service in Console App

    Thank you Martin for the information.

    I am new to Dynamics AX do not know different between the document service and custom service.

    In our AX 2012 version we could not find any service related to Contacts or Customers, do we have our of box services already build for Customers and Contacts? Do they have any particular standard names?

    The below code is generating errors. I am not sure exactly what is missing.

               ContactPersonsServiceClient client = new ContactPersonsServiceClient();
               CallContext context = new CallContext();
               context.Company = "xxx";
               AxdContactPersons contactPersons = new AxdContactPersons();
               AxdEntity_ContactPerson[] contacts = new AxdEntity_ContactPerson[1];
               AxdEntity_ContactPerson contact = new AxdEntity_ContactPerson();
               contact.AssistantName = "Test Assistant";
               //contact.CustAccount = "xxxx";
               //contact.ContactForPartyCustAccount = "xxxx";
               contact.ContactForParty = "xxx";
               contact.Department = "xxx";
               //Set the name fields
               AxdEntity_PersonName personName = new AxdEntity_PersonName();
               personName.FirstName = "ContactFTest";
               personName.MiddleName = "MiddleTest";
               personName.LastName = "LastTest";
               AxdEntity_Person_DirPerson person1 = new AxdEntity_Person_DirPerson();
               person1.NameAlias = "ContactFTest";
               person1.NameSequence = "FirstMiddleLast";
               person1.PersonName = new AxdEntity_PersonName[1] { personName };
               contact.Person = new AxdEntity_Person_DirPerson[1] { person1 };
               //contact.Party = "xxxx";
               contacts[0] = contact;
               contactPersons.ContactPerson = contacts;
               try
               {
                   client.create(context, contactPersons);
                   Console.WriteLine("Write Completed");
                   Console.ReadLine();
               }
               catch (Exception e)
               {
                   Console.WriteLine("Exception : {0}", e.Message);
                   client.Abort();
               }

    The below code works and creates a customer in the AX

               CustomerServiceClient client =  new CustomerServiceClient();
               CallContext context = new CallContext();
               context.Company = "xxx";
               AxdCustomer customer = new AxdCustomer();
               AxdEntity_CustTable custTable = new AxdEntity_CustTable();
               custTable.CustGroup = "xxx";
               custTable.AccountNum = "xxxx";
               custTable.Currency = "xx";
               custTable.TaxGroup = "xxx";
               custTable.VATNum = "BExxxxxxxxxx";
               /*custTable.OneTimeCustomer = AxdExtType_OneTimeCustomer.Yes;
               custTable.OneTimeCustomerSpecified = true;*/
               AxdEntity_DirParty_DirOrganization org = new AxdEntity_DirParty_DirOrganization();
               org.Name = "Test Org Name 2";
               custTable.DirParty = new AxdEntity_DirParty_DirPartyTable[1] { org };
               customer.CustTable = new AxdEntity_CustTable[1] { custTable };
               try
               {
                   client.create(context, customer);
                   Console.WriteLine("Write Completed");
                   Console.ReadLine();
               }
               catch (Exception e)
               {
                   Console.WriteLine("Exception : {0}", e.Message);
                   client.Abort();
               }

    I am not able to figure out why contact is not created?

    I created a contact manually in AX system and it is taking only few fields

    1) Contact For field => A drop down to Party,

    2) First Name,

    3) Middle Name and

    4) Last Name.

  • Martin Dráb Profile Picture
    231,777 Most Valuable Professional on at
    RE: Consume AX Web service in Console App

    Your code is for a document service, not a custom service. So let me ask you: why exactly did you create your own document service instead of using the existing one? You probably have a problem in your new document service, and you shouldn't waste time with trying to fix it if it shouldn't exist at all.

    By the way, please always use Insert > Code (in the rich-formatting view) to paste source code. It'll be much easier to read and work with.

  • Abhi R Profile Picture
    20 on at
    RE: Consume AX Web service in Console App

    I am able to create a customer with new service which we created

    CustomerServiceClient client =  new CustomerServiceClient();

               CallContext context = new CallContext();

               context.Company = "xxx";

               AxdCustomer customer = new AxdCustomer();

               AxdEntity_CustTable custTable = new AxdEntity_CustTable();

               custTable.CustGroup = "xxx";

               custTable.AccountNum = "xxxx";

               custTable.Currency = "xx";

               custTable.TaxGroup = "xxx";

               custTable.VATNum = "BExxxxxxxxxx";

               /*custTable.OneTimeCustomer = AxdExtType_OneTimeCustomer.Yes;

               custTable.OneTimeCustomerSpecified = true;*/

               AxdEntity_DirParty_DirOrganization org = new AxdEntity_DirParty_DirOrganization();

               org.Name = "Test Org Name 2";

               custTable.DirParty = new AxdEntity_DirParty_DirPartyTable[1] { org };

               customer.CustTable = new AxdEntity_CustTable[1] { custTable };

               try

               {

                   client.create(context, customer);

                   Console.WriteLine("Write Completed");

                   Console.ReadLine();

               }

               catch (Exception e)

               {

                   Console.WriteLine("Exception : {0}", e.Message);

                   client.Abort();

               }

  • Abhi R Profile Picture
    20 on at
    RE: Consume AX Web service in Console App

    Hello Martin, Yes we create new inboundport and i am trying to create a contact with below code it is not working.

    ContactPersonsServiceClient client = new ContactPersonsServiceClient();

               CallContext context = new CallContext();

               context.Company = "xxx";

               AxdContactPersons contactPersons = new AxdContactPersons();

               AxdEntity_ContactPerson[] contacts = new AxdEntity_ContactPerson[1];

               AxdEntity_ContactPerson contact = new AxdEntity_ContactPerson();

               contact.AssistantName = "Test Assistant";

               //contact.CustAccount = "xxxx";

               //contact.ContactForPartyCustAccount = "xxxx";

               contact.ContactForParty = "xxx";

               contact.Department = "xxx";

               //Set the name fields

               AxdEntity_PersonName personName = new AxdEntity_PersonName();

               personName.FirstName = "ContactFTest";

               personName.MiddleName = "MiddleTest";

               personName.LastName = "LastTest";

               AxdEntity_Person_DirPerson person1 = new AxdEntity_Person_DirPerson();

               person1.NameAlias = "ContactFTest";

               person1.NameSequence = "FirstMiddleLast";

               person1.PersonName = new AxdEntity_PersonName[1] { personName };

               contact.Person = new AxdEntity_Person_DirPerson[1] { person1 };

               //contact.Party = "xxxx";

               contacts[0] = contact;

               contactPersons.ContactPerson = contacts;

               try

               {

                   client.create(context, contactPersons);

                   Console.WriteLine("Write Completed");

                   Console.ReadLine();

               }

               catch (Exception e)

               {

                   Console.WriteLine("Exception : {0}", e.Message);

                   client.Abort();

               }

  • Martin Dráb Profile Picture
    231,777 Most Valuable Professional on at
    RE: Consume AX Web service in Console App

    Okay, so you've decided not to the standard document service and you rather create a custom service (not a document service) doing something similar.

    You didn't mention generating CIL and configuring an inbound port. Have you done that?

  • Abhi R Profile Picture
    20 on at
    RE: Consume AX Web service in Console App

    Dear Martin,

    Thank you for the information. We created a custom service in AX it is called ContactPersonService and i added it in the Console app in the service reference.

    and when i am executing the request

    i am getting the below error

    "Could not connect to \"net.tcp://*****:8201/DynamicsAx/Services/ContactPersonServices\". The connection attempt lasted for a period of 00:00:21.0037801. TCP error code 10060: A connection attempt failed because the remote party did not properly respond after a period of time, or the established connection failed because the connected host did not respond AX Server IP Address:8201."

    Do you have any idea?

    Regards,

    Abhilash

  • Martin Dráb Profile Picture
    231,777 Most Valuable Professional on at
    RE: Consume AX Web service in Console App

    Do you mean AIF document services? There already is a standard document service for contact persons.

    Are you familiar with WCF? Do you know how to add a service reference in Visual Studio?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,907 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,777 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans