Create and configure the Inbound integration port for CustCustomerService
- Open the Inbound ports form. Click System administration > Setup > Services and Application Integration Framework > Inbound ports.
- Click New.
- Name the new integration port CRM2AXCustCustomerService.
- In the Adapter list in the Address group, select NetTcp.
- On the Service contract customizations FastTab, click Service operations.
- 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.
- 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.
- Activate the integration port.
- Make note of the address that is displayed in the WSDL URI text box.
- Close the Inbound ports form.
Create a C# project to consume the WCF service
- Open Visual Studio and create a new console application project in Visual C#. Name the project "CRM2AXMKClient".
- In Solution Explorer, right-click the project name and then click Add Service Reference.The Add Service Reference dialog box opens.
- 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
- Click Go. Wait for Visual Studio to find the service.
- Click OK to close the dialog box.
- 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
- Build the project. and Run.
You can see the customer has been created in AR-->All Customers.
Happy learning :) ... Mallik
No comments:
Post a Comment