Monday, 20 April 2015

Ax 2012 AIF Calling the CustCustomerService.Create method from WCF C#

Create and configure the Inbound integration port for CustCustomerService

  1. Open the Inbound ports form. Click System administration > Setup > Services and Application Integration Framework > Inbound ports.
  2. Click New.
  3. Name the new integration port CRM2AXCustCustomerService.
  4. In the Adapter list in the Address group, select NetTcp.
  5. On the Service contract customizations FastTab, click Service operations.
  6. In the Select service operations form, select CustCustomerService.create,CustCustomerService.read and CustCustomerService.update in the Remaining service operations list. Click the left arrow to move the service operation to the Selected service operations list. Then, close the form.
  7. You can modify the document data policy to match the fields that you want to return in the response. If you do not specify a data policy, then all sales order schema elements are included in the response message by AIF. If you specify a data policy but do not modify the default data policy, then only the default elements are included in the sales order schema.
  8. Activate the integration port.
  9. Make note of the address that is displayed in the WSDL URI text box.
  10. Close the Inbound ports form.
Create a C# project to consume the WCF service 
  1. Open Visual Studio and create a new console application project in Visual C#. Name the project "CRM2AXMKClient".
  2. In Solution Explorer, right-click the project name and then click Add Service Reference.
    The Add Service Reference dialog box opens.
  3. In the Address text box, enter the WSDL URI from the port that you created in the previous section. For example:
    http:// XXXXMKAOSXX:8101/DynamicsAx/Services/CRM2AXCustCustomerService
    
  4. Click Go. Wait for Visual Studio to find the service.
  5. Click OK to close the dialog box.
  6. Open Program.cs. In the code editor, replace the code with the following C# code:

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

namespace CRMCustCustomerServiceCreate
{
    class Program
    {
        ///



        /// This method is used to create a customer in Dynamics AX using AIF WCF service CustCustomerService.
        ///
        ///
        static void Main(string[] args)
        {
            try
            {
                // Try to create the customer.
                // Display the information for the customer.
                Console.WriteLine("Creating the customer : MK2" );
                WebServiceTest();
            }
            catch (Exception e)
            {
                // Display the exception message. 

                Console.WriteLine("Exception: " + e.Message);
               // c1.Abort();
            }
        }
        ///



        /// Customizaton added by Mallikarjun Gudidevuni on 20/04/2015
        ///
        static void WebServiceTest()
        {
            //ServiceReference1 is the name of ServiceReferance added to the project.
            using (ServiceReference1.CustomerServiceClient custClient = new ServiceReference1.CustomerServiceClient())
            {
                var context = new ServiceReference1.CallContext() { Company = "USMF" };
                var customers = new ServiceReference1.AxdCustomer
                {
                    CustTable = new ServiceReference1.AxdEntity_CustTable[] 
                                    { 
                                        new ServiceReference1.AxdEntity_CustTable() 
                                        { 
                                            CustGroup="10", 
                                            TaxGroup="NY", 
                                            AccountNum = "MK2",
                                            Currency = "USD",                                         
                                            DirParty = new ServiceReference1.AxdEntity_DirParty_DirPartyTable[1] 
                                            {
                                                new ServiceReference1.AxdEntity_DirParty_DirOrganization() 
                                                    { LanguageId = "en-us", Name = "Mallikarjun" }
                                            }// end of Dir
                                        }//end of ASD_CustTable()
                                    }//endof CustTable
                };//end of Customers
               
                custClient.create(
                  context,
                  customers
                  );
                custClient.Close();
            } //endof using 
        }//end of WebServiceTest
    }
}

            
               
Build the project and run
  1. Build the project. and Run.
              You can see the customer has been created in AR-->All Customers. 


Happy learning :) ...   Mallik
           
           

No comments:

Import and Export file from BLOB storage Account(Azure) in D365 F&O using X++

  Import and Export file from BLOB storage Account in D365 F&O using X++ Import: /// <summary> /// MKInventQualityOrderLineService...