In this article, we are going to learn how to build a custom service in d365 and how to use It
Introduction
So what is a custom service?
It is a feature provided by D365 F&O to expose its functionality outside of the environment to facilitate users using it on other platforms (mobile apps and web apps) to meet their required business process requirements
How it works
A custom service deployed in d365 acts the same as an API does
In D365, a custom service is deployed on the following two endpoints at the same
JSON endpoint
SOAP endpoint
Let’s begin
STEP 1: Request Contract
Firstly, we need a contract class for request deserialization
A sample contract class is here
[DataContract]
public class PurchaseOrderRequest
{
PurchId purchId;
DataAreaId dataAreaId;
[DataMember]
public PurchId parmPurchId(PurchId _purchId)
{
purchId = _purchId;
return purchId;
}
[DataMember]
public DataAreaId parmDataAreaId(DataAreaId _dataAreaId)
{
dataAreaId = _dataAreaId;
return dataAreaId;
}
}If your request has fewer parameters then you can continue by skipping the contract request class
STEP 1: Response Contract
Then, we need the response contract class for response deserialization
Sample response contract class is here
[DataContract]
public class PurchaseOrderResponse
{
VendAccount vendAccount;
VendName vendName;
DlvDate dlvDate;
PurchStatus status;
PurchaseType purchaseType;
[DataMember]
public VendAccount parmVendAccount(VendAccount _vendAccount)
{
vendAccount = _vendAccount;
return vendAccount;
}
[DataMember]
public VendName parmVendName(VendName _vendName)
{
vendName = _vendName;
return vendName;
}
[DataMember]
public DlvDate parmDlvDate(DlvDate _dlvDate)
{
dlvDate = _dlvDate;
return dlvDate;
}
[DataMember]
public PurchStatus parmStatus(PurchStatus _status)
{
status = _status;
return status;
}
[DataMember]
public PurchaseType parmPurchaseType(PurchaseType _purchaseType)
{
purchaseType = _purchaseType;
return purchaseType;
}
}If your request has fewer parameters then you can continue by skipping the contract request class
STEP 1: API Class (The Service Class)
Lastly, we have to develop a service class to participate in API operations
The sample service class is here
public class PurchaseOrderInfo
{
public PurchaseOrderResponse getPurchaseOrderData(PurchaseOrderRequest purchaseOrder)
{
PurchaseOrderResponse response;
PurchTable purchTable;
;
changecompany(purchaseOrder.parmDataAreaId())
{
purchTable = PurchTable::find(purchaseOrder.parmPurchId());
response = new PurchaseOrderResponse();
response.parmVendAccount(purchTable.OrderAccount);
response.parmVendName(purchTable.PurchName);
response.parmDlvDate(purchTable.DeliveryDate);
response.parmStatus(purchTable.PurchStatus);
response.parmPurchaseType(purchTable.PurchaseType);
}
return response;
}
}STEP 1: Service
Create a service element, assign your service class to it, and select the name
add new service operation and select a related method from the service class as below