Thursday, April 30, 2015

how to quickly enble impersonated current user to consume the Dynamic AX web service?

My web app is running under the Application Pool assoicated with a specific account, it is perfectly fine to consume the Dynamic AX web serivce.

However, the records were created in the Dynamic AX by the service account after we call the web service to send data to Dynamic AX. if we want to show the record was created the people who run the web application. we can use LogonAsUser property from the CallContext Object. we have to modify the web application by adding following line of code. i highlighted this line of code in Bold

FreeTextInvoiceService2012Http.CallContext context = new FreeTextInvoiceService2012Http.CallContext();
context.LogonAsUser = "YourDomain\\userName";
 textInvoiceService.ClientCredentials.Windows.ClientCredential.UserName = GetAppSettingsValue("UserName"); //which is the serivce account that allow to consume the dax web service
textInvoiceService.ClientCredentials.Windows.ClientCredential.Password = GetAppSettingsValue("Password");


in the Dynamic side,we must configure this service account to be allow impersonation. and grant the user name a role that allow to access the Dynamic AX.

when you check the TextFreeInvoice Tabale in dynamic AX, you should be able to see the user ID instead of the service account ID in the CreatedBy columns

Happy Programming.





No comments:

Post a Comment