Creating a custom service

Rumman Ansari   Software Engineer   2024-11-02 11:36:12   107  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

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;
    }

}
Creating Custom Service - Create Request Class
Figure: Creating Custom Service - Create Request Class

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;
    }

}
Creating Custom Service - Create Response Class
Figure: Creating Custom Service - Create Response Class

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;
        }
    }

}
Creating Custom Service - Create a Service class
Figure: Creating Custom Service - Create a Service class

Create a Service with Service Operations

Creating Custom Service - Create a Service with Service Operations
Figure: Creating Custom Service - Create a Service with Service Operations

Create Service Group

Creating Custom Service - Create Service Group
Figure: Creating Custom Service - Create Service Group

Test Using Postman tool, Send Request and Get Response

Creating Custom Service - Test Using Postman tool, Send Request and Get Response
Figure: Creating Custom Service - Test Using Postman tool, Send Request and Get Response

Request

{           
 "_request":
 {
    "DataAreaId":"DAT"
 }            
}
Response

{
    "$id": "1",
    "ErrorMessage": "",
    "Success": true,
    "DebugMessage": "Hello World"
}
MCQ Available

There are 1 MCQs available for this topic.

1 MCQ