Create and configure the Inbound integration port for CustCustomerService.Update
- 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:
4. 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 CRM2AXUpdateCustCustomerService
{
class Program
{
//Mallik Code to updated Customer using WCF (CustCustomerService.update()) 20/04/2015
// The customer service is date effective because it contains the DirPersonName, DirOrganizationName,
//DirPartyLocation, etc. tables which have their ValidTimeStateFieldType properties set to something other than None.
//Date effective services have properties added at the document level (the highest level in the service)
//to indicate how you want to set the date effective entities.
//The properties are ValidTimeStateType, ValidAsOfDateTime, ValidFromDateTime and ValidToDateTime.
//Either you can set those at the document level or you can set the date effective fields on each entity in the service
//that is date effective.
//In the example code below, I call the read method to retrieve a customer and then I create a
//new instance of a customer, set the date effective properties on the document according
//to what they are on the retrieved customer and then update the CreditMax field on the customer.
static void Main(string[] args)
{
string customer = "MK2";
//ServiceReference1 is the name of ServiceReferance added to the project.
ServiceReference1.CustomerServiceClient proxy = new ServiceReference1.CustomerServiceClient();
var context = new ServiceReference1.CallContext() { Company = "USMF" };
ServiceReference1.AxdCustomer foundCustomer = null;
try
{
foundCustomer = proxy.read(context, readCritera(customer));
Console.WriteLine("Read worked");
updateCustomer(foundCustomer);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
} // end of Main
private static ServiceReference1.EntityKey[] readCritera(string customerAccount)
{
ServiceReference1.AxdEntity_CustTable custTable = new ServiceReference1.AxdEntity_CustTable();
ServiceReference1.EntityKey[] entityKeyList = new ServiceReference1.EntityKey[1];
ServiceReference1.EntityKey key = new ServiceReference1.EntityKey();
ServiceReference1.KeyField[] keyFields = new ServiceReference1.KeyField[1];
ServiceReference1.KeyField keyField = new ServiceReference1.KeyField();
keyField.Field = "AccountNum";
keyField.Value = customerAccount;
keyFields[0] = keyField;
key.KeyData = keyFields;
entityKeyList[0] = key;
return entityKeyList;
}
private static void updateCustomer(ServiceReference1.AxdCustomer customer)
{
ServiceReference1.CustomerServiceClient proxy = new ServiceReference1.CustomerServiceClient();
ServiceReference1.CallContext context = new ServiceReference1.CallContext();
context.Company = "USMF";
ServiceReference1.AxdEntity_CustTable custTable = customer.CustTable[0];
ServiceReference1.AxdCustomer axdCustomer2 = new ServiceReference1.AxdCustomer();
axdCustomer2.ValidTimeStateType = customer.ValidTimeStateType;
axdCustomer2.ValidTimeStateTypeSpecified = true;
axdCustomer2.ValidAsOfDateTime = customer.ValidAsOfDateTime;
axdCustomer2.ValidFromDateTime = customer.ValidFromDateTime;
axdCustomer2.ValidToDateTime = customer.ValidToDateTime;
ServiceReference1.AxdEntity_CustTable custTableNew = new ServiceReference1.AxdEntity_CustTable();
custTableNew._DocumentHash = custTable._DocumentHash;
custTableNew.RecId = custTable.RecId;
custTableNew.RecVersion = custTable.RecVersion;
custTableNew.action = ServiceReference1.AxdEnum_AxdEntityAction.update;
custTableNew.actionSpecified = true;
custTableNew.CreditMax = custTable.CreditMax + 10;
custTableNew.CreditMaxSpecified = true;
custTableNew.CustGroup = custTable.CustGroup;
axdCustomer2.CustTable = new ServiceReference1.AxdEntity_CustTable[1] { custTableNew };
try
{
proxy.update(context, readCritera("MK2"), axdCustomer2);
Console.Write("Worked");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Failed");
Console.ReadLine();
}
}
}
}
For Item /Product Refer
https://blogs.msdn.microsoft.com/dynamicsaxscm/2011/07/06/product-item-data-management-services/
https://blogs.msdn.microsoft.com/dynamicsaxscm/2011/07/06/product-item-data-management-services/