Thursday, May 5, 2022

Create a custom web service in D365FO Integration (Data Receiving)

Create a Table where you want to insert the fields in my case I am creating a table GITS_Worker, which has 2 fields "Name" and "Number"


Now create a contract class, in my case, I am naming my contract class "GITSCreateWorker" and write the following code:

-------------------------------------------------------START------------------------------------------------------------

[DataContractAttribute]

class GITSCreateWorker

{

    Name Number;

    Name Name;

    [DataMemberAttribute]

    public str Number(str _Number= Number)

    {

        Number = Number;

        return Number;

    }

    [DataMemberAttribute]

    public str Name(str _Name= Name)

    {

        Name = Name;

        return Name;

    }

}

------------------------------------------------------------END----------------------------------------------------------

Now create a class for inserting data in a table, in my case, I am naming my class "GITSWorkerIntegrationService" and write the following code:

-------------------------------------------------------START------------------------------------------------------------

class GITSWorkerIntegrationService

{

 [AifCollectionTypeAttribute('_CreateWorker',Types::Class,classStr(GITSCreateWorker)),SysEntryPointAttribute(true)]

    public Str CreateWorker(List    _CreateWorker)

    {

        GITSCreateWorker        CreateWorker;

        Enumerator              EnumeratorHeader;

        GITS_Worker             Worker;

        EnumeratorHeader    = _CreateWorker.getEnumerator();

        while(EnumeratorHeader.moveNext())

        {

            CreateWorker    = EnumeratorHeader.current();

            Worker.Name     = CreateWorker.Name();

            Worker.Number   = CreateWorker.Number();

            Worker.insert();

        }

        return "Success";

    }

}

------------------------------------------------------------END----------------------------------------------------------


Now create an AxService, in my case I am creating "GITSWorkerIntegrationService"

In the properties of this service put in the name of the class that we created "GITSWorkerIntegrationService"

Now put in the description property

Now right click on "Service operation" and create a new service operation, in the properties of this service operation put in the name of the method that we created

Now create an AxServiceGroup, in my case I am creating "GITSWorkerIntegrationServiceGroup"

In the properties set auto-deploy yes and put in the description

Now create a new "Service" in the group and put in the AxService that we created

Sync and build 

Tada !!!

Now your web service is ready to use. use below urls for respective services

<D365FO URL>/api/services/<Service group name>/<Service Name>/<Service operation name>

<D365FO URL>/soap/services/<Service group name>?wsdl