Search This Blog

Saturday 11 October 2014

Create First Custom Service In Microsoft Dynamics AX 2012

There is very good blog available for creating the Custom Services in Microsoft Dynamics 2012.

http://sumitsaxfactor.wordpress.com/2012/05/19/create-your-first-custom-service-ax-2012/


One thing I just wanted to mention here that is not given in this blog is:

While consuming your newly created service outside AX in your C# or any other code you need to specify the company name in which your x++ service code will execute.

if just pass the code as mention in above blog post i.e

string[] custIds = servClient.retrieveCustomerNames(new SamCustomAXService.CallContext(), strItem);  

than your code will run in dat company which by default set in AX and it contains no data therefore it will not return any data which you want.

To run your x++ service code in your specified company than you have to create the object of call context and in that object specify your company. You can see the below code for reference.

In my case I have specified the ceu company.

 mzkCustomerService.CallContext context = new mzkCustomerService.CallContext { Company = "ceu" }; 

and than pass this context object in your code as below:

string[] custIds = servClient.retrieveCustomerNames(context, strItem);  
 

This was all related to the Custom Services.

Thanks

Muhammad Zahid.