Creating a custom service
Table of Content:
Custom service development
You can develop custom services for finance and operations. When a developer writes a custom service under a service group, the service group is always deployed on two endpoints:
- SOAP endpoint
- JSON endpoint
In Dynamics 365 for Finance and Operations, we still have custom services available to expose the system's functionality to the external world. Microsoft uses the SysOperation framework, where data contracts are decorated with standard attributes, and it automatically serializes and desterilizes data that is shared between two applications. Any service method can be exposed to the external world by using SysEntryPointAttribute and then specifying the service operation under Application Explorer | AOT | Services.
Create Request Class
[DataContractAttribute] class ansariRequestClass { private str dataAreaId; [DataMember("DataAreaId")] public str parmDataAreaId(str _value = dataAreaId) { if (!prmIsDefault(_value)) { dataAreaId = _value; } return dataAreaId; } }
Create Response Class
[DataContractAttribute] class ansariResponseClass { private boolean success; private str errorMessage; private str debugMessage; [DataMember("ErrorMessage")] public str parmErrorMessage(str _value = errorMessage) { if (!prmIsDefault(_value)) { errorMessage = _value; } return errorMessage; } [DataMember("Success")] public Boolean parmSuccess(Boolean _value = success) { if (!prmIsDefault(_value)) { success = _value; } return success; } [DataMember("DebugMessage")] public str parmDebugMessage(str _value = debugMessage) { if (!prmIsDefault(_value)) { debugMessage = _value; } return debugMessage; } }
Create a Service class
public class ansariServiceClass { public ansariResponseClass create(ansariRequestClass _request) { var response = new ansariResponseClass(); changecompany(_request.parmDataAreaId()) { try { response.parmDebugMessage("Hello World"); response.parmSuccess(true); } catch (Exception::CLRError) { System.Exception interopException = CLRInterop::getLastException(); response.parmSuccess(false); response.parmErrorMessage(interopException.ToString()); } return response; } } }
Create a Service with Service Operations
Create Service Group
Test Using Postman tool, Send Request and Get Response
Request
Response{ "_request": { "DataAreaId":"DAT" } }
{ "$id": "1", "ErrorMessage": "", "Success": true, "DebugMessage": "Hello World" }