Step by Step: Create the Data Contract Class
1.
Open Microsoft Dynamics AX 2012.
2.
Open a Developer workspace.
3.
Open the AOT.
4.
Create a new class named AddressFinder.
5.
Enhance the class by adding the [DataContractAttribute] attribute.
6.
Enter a method called Address which returns the address.
7.
Enhance the method by adding the [DataMemberAttribute] attribute.
X++:
[DataMemberAttribute]
public str address()
{
return "Demo Address";
}
Step by Step: Create the X++ Service Class
1.
Create a new class named AddressUtility. This is the service class.
2.
Create a public method named getNearestLocation. This method instantiates the AddressFinder object and returns the AddressFinder object.
3.
Enhance the class by adding the [SysEntryPointAttribute] attribute.
X++:
[SysEntryPointAttribute]
public AddressFinder getNearestLocation()
{
AddressFinder addressFinder = new AddressFinder();
return addressFinder;
}
Step by Step: Create the Service
1.
Right-click the Services node in the AOT and select New Service.
2.
Change the Name property to AddressService.
3.
Set the Class property to AddressUtility.
4.
Expand the AddressService service node.
5.
Right-click the Operations node and select Add Operations.
6.
Check the Add checkbox and click OK.
7.
Right-click the Services Group node in the AOT and select New Service Group.
8.
Change the Name property to AddressServiceGroup.
9.
Drag the service under the service group node.
10.
Right-click the AddressServiceGroup service group and select Deploy service group.