Custom service, with in Ax plays a vital role in exposing X++ code to the external party i.e exposing X++ code to the HTML client for the web app.
To understand, lets first split in the components that we require.
1) Contract class
2) Service class
Scenario 1: Create Purchase Order from SalesOrder
1) Contract class: The purpose for the contract class, is by using this, data coming from the 3rd party client i.e HTMl web client to AX OR going from the AX to the HTML web client is done using contract class, which is used by the service class.
So I have create a contract class
I have also created parm* method, I need this for to expose the fields to the external client.
Note: I have made access Modifiers as “public”
DataContractAttribute: It is used for the class to be treated a contract class.i.e Serialization/Desrialization of the data
DataMemberAttribute: Done for every parm method, becuase by doing this.. parm* method will be exposed as a property to the external.
2) Service class: It is our main class, which interacts with the client.
Note: RunOn = Server
For CreatePurchaseOrder from SalesOrder
SysEntryPointAttribute: We use this attribute for 1) method to be available as a operation of the service, if we dont set this parameter method will not be availbale to be exposed. 2) We set ‘true/false’ in the attribute to validate the access level of the method to the respective tables used in the tables.
AifCollectionTypeAttribute: We use Use the AifCollectionTypeAttribute attribute for X++ Collection type(List,Map e.t.c) which are used as a inpurt or as a return value from or parameter to a service operation.
You can see how i used the ‘purchAutoCreate’ class which is the existing class for the creation of purchase order.
Scenario 2: Confirm Purchase Order
Note: After creation of the service class we need to generate IL for the xpp files to be created in the source folder.
Finally for service class to be used as a service we need to create a service within the service node in AOT and set the class property to the service class that we have created.
By selecting the service class in the class property, all the method which are exposed will be available for the service to be select BY right clicking and adding a method.
Once it is done we need to register the service by right click the service i.e ASMMzkPurchDetailHeaderService>Add-ins>Register service
Go to SystemAdministration>Setup>Services and Application Integration Framework >Inbound ports
Click New, Give the service name and description.
select the url, port on which the service will be exposed
For operations to be selected, click on the “Service operation” button
Here we see all the operations that we have added from the service node
Once we selected the operation, we are all good to activate the port and have the WSDL url to be used for the external client.
Please let me know for any help, Thanks