Friday, 26 April 2013

Error when debugging Services class method from X++

Recently one of our developer came to me with an error that he was getting while trying to debug a class method that was used as a service. The error that he was getting was

'unchecked' cannot be called on the client.

The code for the service class method was something like below.

 public ProductsDataContract getItemById(ItemId _itemId)  
   qrInventTable = new QueryRun(queryInventTable);  
   while (  
   return productsDataContract;  

There is nothing unusual about it. As expected it have the SysEntryPointAttribute(true) declared at the beginning of the method. As soon as he started to debug this method from an X++ job, AX will throw the above mentioned error on the first line of the method. However if he comment out the attribute line, he could debug it with no error.

This was bit unusual as I never came across to this type of error before. With a little investigation I found that the service class was not marked to run on Server instead the RunOn property was left to default "Called from" (which would work fine for a WCF call as the call always goes to AOS but will not work from an X++ call from a job). For services it is a must that the service class should be marked to run on Server as shown below.

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

1 comment:

  1. Very interesting. And the solutions also is quite tricky. Never would thought about it. But it's not my level of programming anyway. Good for You that You still work on microsoft dynamics erp systems. Hope this project will be developing for a long time yet.