Calling A Restful Service From Dynamics AX 2012
Broadly there are three tasks which need to be done/required.
1. RESTful service & its complete parameter signature
2. VS API which calls this service
3. AX code which calls the VS API
I tried it with JSON based services. Unfortunately, I do not have any tool which can parse a JSON request and create a proxy for me (as I have for SOAP based services). So, I have to manually write code to format the service parameter string. For this reason it is very important to have correct format of request – from header to full body with all syntax. One punctuation mistake may end up in debugging nightmare.
In VS create a new project of type ‘Class library’. In this project create a public method which takes parameters from AX, calls the web service and return result to AX. Keep the incoming parameters as simple data type like string, int, double etc. as they easily marshalled between X++ and C#. Use arrays if needed in parameters. Create a separate method (private) for formatting web service parameter string. As the logic for formatting string can be complicated it is advisable to keep it separate from caller code. The API method will call this formatter method as needed. Use enough try catch in the API method as web services often throws errors for various reasons and there should not be any unhandled error.
Now deploy the VS project to AX. Make sure that assemblies at both server and client are updated.
Create a class in AX which calls the VS API with required parameters.