Contents

Response in AIF custom service class

At the previous post I already show how to customize Response Value list in AIF Document standard service, today we will talk about response in Custom AIF service class.

We already know for Custom AIF service we actually need 2 classes, one is contract for data input and one is service to process a logic. With Response class, it’s literally same with contract class. They both hold parm value.

  • contract class gets parametters.

  • Response class sets return values.

1. Scenario

I want to get HcmPersonnelNumberId and HcmWorkerName of current userID on C#.NET application.

2. Solution

  • Write Custom AIF service to get Worker information, and then public this service.

  • Write C#.NET console to consume that service.

3. Walkthrough

3.1. Response class

1
2
3
4
5
6
[DataContractAttribute]
class MaxWorkerResponse
{
    str     gId;
    str     gName;
}

two value that I want to return is HcmPersonnelNumberId and HcmWorkerName, I will store it in 2 parms method

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
[DataMemberAttribute('HcmWorkerName')]
public HcmWorkerName parmName(HcmWorkerName _name = gName)
{
    gName = _name;

    return gName;
}

[DataMemberAttribute('HcmPersonnelNumberId')]
public HcmPersonnelNumberId parmId(HcmPersonnelNumberId _id = gId)
{
    gId = _id;

    return gId;
}

3.2. Service class

Create MaxPRService Class, This class consume through service that need to be extend SysOperationServiceBase class

1
2
3
class MaxPRService extends SysOperationServiceBase
{
}

Main logic

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
[SysEntryPointAttribute(true),
AifCollectionTypeAttribute('return', Types::String)]
public MaxWorkerResponse getEmployee()
{
    HcmWorkerRecId          workerRecId;
    HcmPersonnelNumberId    personnelNumber;
    HcmWorkerName           name;
    MaxWorkerResponse       response;

    workerRecId = DirPersonUser::currentWorker();
    personnelNumber = HcmWorker::find(workerRecId).PersonnelNumber;
    name = HcmWorker::find(workerRecId).name();
    
    response = new MaxWorkerResponse();
    
    response.parmId(personnelNumber);
    response.parmName(name);
    
    return response;
}

3.3. Create service

In AOT create new service and add recent created class to that Service, in operations node add getEmployee method, you will get something likes

/2017-01-12-respone-in-aif-custom-service-class/Respone-in-AIF-custom-service-class-1.png

Then right click service > Add-ins > Register Service.

go to AIF inbound form to create new service and add getEmployee operation to that service then Active.

3.4. Consume service

Add recent WSDL URI http://WINSERVER:8104/DynamicsAx/Services/MaxPurchReqGeneral into Service reference in C# Console project

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
static void Main(string[] args)
{
	CallContext context = new CallContext()
	{
		Company = "USMF",
		Language = "EN-US",
	};
	
	MaxPRServiceClient client = new MaxPRServiceClient();
	MaxWorkerResponse response = client.getEmployee(context);
	
	Console.WriteLine(response.HcmWorkerName + ", " + response.HcmPersonnelNumberId);
	Console.ReadLine();
}

Thank you for reading.