Custom Web Service in Microsoft Dynamics 365 Finance and Operations

This blog describes the process of creating a custom web service in Dynamics 365 Finance and Operations.

Introduction:

Web services are basically Web APIs that are used to GET or POST data in D365 FO. There are some standard web services included in FO but users can create their custom web service to utilize it in a third-party application.

In the following steps, we will define how to create a custom web service for creating a transfer journal from a third-party application through a web service in JSON format.

Initial Steps:

1. Create a new model and project or utilize an already created project. Add a Data Contract class in the project which will contain the properties (table columns) needed for inserting data when creating a transfer journal in D365 FO.

2. Add the following code and define the Data Member Attribute properties in each parm method.

3. After creating a Data Contract class which will act as a model for passing the values in and out of web service. Now create a service class that contains the business logic of the web service. In our case, it will contain a Post method that takes data contract, extract data from it, and maps it into D365 tables.

Creating Service and Service Group

1. After the data contract and service class, you will need to create a service that will hold the class and expose its method as consumable APIs.

2. Go into service properties and select the service class with which you want this service to be associated with.

3. After assigning the class add a new service operation in the created service and select the desired method in the properties. Service operation is basically the methods in the class which is exposed as getting and Post methods.

4. Once the service is configured, add a service group. A service group contains a service or a group of services and act as an endpoint to call the exposed methods through external resources.

5. Add the service created in the above steps into the service group.

Calling the web service:

To call the web service following URL will be used:

https://<D365 URL>/api/services/TransJourServiceGroup/TransJourService/createTransferJournal

Let’s break down this URL into parts.

  • HTTPS:// – This specifies we are making a secure call.
  • <D365 URL> – This should be replaced by the URL used to access your D365 environment. For example https://usnconeboxax1aos.cloud.onebox.dynamics.com
  • API/services – This text tells D365 that we are calling a service.
  • TransJourServiceGroup – This is the name of the service group we are calling.
  • TransJourService – This is the name of the service we are calling.
  • createTransferJournal – This is the name of the method we are calling on the Service class.

 

Conclusion:

Through the above-mentioned steps, you can create any GET and POST type web service and integrate it into any external application using REST APIs.

Related Post