Friday, 2 August 2013

WCF worker session inactivity timeout

One of the new features of Dynamics AX2012 was introduction of WCF services. Our organisation's current website uses BC.Net to integrate with AX. We are in the process of porting it to WCF.

When the customers are placing orders on our website one of the step is to show the product they regularly buy combined with the most popular products. To provide a fast experience to the customers we decided to use multiple simultaneous calls to AX to get the product details along with the stock check already done on these products. As these customers are external to our organisation hence we create these customers as Claim based users in AX (another new feature in AX2012) and apply xds security policy to filter out only the data that a particular customer is allowed to see.

This worked very well until we noticed that these simultaneous calls, for a customer, results in creation of multiple worker sessions in AX. AOS does reuses these sessions if they are free. If the session is busy serving a request AOS creates another session. In our case the duration of each request for an item, with its details, is around 200 milliseconds, so a page with 100 items resulted in 10-15 worker sessions. What we observed was that these sessions lasted for 30 minutes despite the request being completed in milliseconds.

This was a potential problem for us. With a customer base of more than 70 thousand customers, the AOSs could potentially be flooded with sessions that are not being used and could hit the upper limit of maximum concurrent sessions on an AOS very quickly (by default set at 2000, but can be changed). Once that limit is hit AOS refuses any more connection request and throws an error.

We tried to find whether this 30 minute inactivity time out can be changed to a value which is more convenient for us but failed to find any such setting. So we contacted Microsoft and they recommended the following change. To configure the WCF worker session inactivity time out on an AOS add the line

 <add key="SessionPoolFlushSeconds" value="180" />

to the <appSettings> section of file Ax32Serv.exe.config located at

C:\Program Files\Microsoft Dynamics AX\60\Server\<AOS NAME>\bin

A restart of AOS is required for the change to take effect. After the change the file should look similar to

As can be seen from the file we set it to clean up after 3 minutes. The clean up happens 3 minutes after the time the worker session is last used. So if a worker session is first created at 12:00 and then reused at 12:02, it will be cleaned after 12:05.

Note: Please be very cautious in making this change. Proper testing should be done before deploying the change to the production AOS(s). Setting a very low value could result in poor performance as AOS will have to recreate the session which is a time consuming task.

This posting is provided "AS IS" with no warranties. Use code at your own risk.


  1. It says access denied .. though i make changes with admin access.

    1. Please try the following

      Make sure the AOS is stopped.
      Check that the file is not Read-Only.
      Open the notepad by Right click\Run as administrator.

      If all the above is fine and still you cannot edit the file then check the security rights on the file and give your user full permission on the file.