Friday, December 9, 2022

Create a custom web service in D365FO Integration (Data Sending) Outbound

Share the data of a table using soap services

In our case let's create a table DAP_Worker with the fields Name, Phone, Address

Now create a class "GITSWorkerList"


[DataContractAttribute]

class GITSWorkerList

{

    Name    Name;

    Name    Phone;

    Name    Address;


    [DataMemberAttribute]

    public Name Name(Name _Name = Name)

    {

        Name = _Name;

        return Name;

    }


    public Name Phone(Name _Phone = Phone)

    {

        Phone = _Phone;

        return Phone;

    }


    public Name Address(Name _Address = Address)

    {

        Address = _Address;

        return Address;

    }


}



Now create a service class "GITSWorkerService"

class GITSWorkerService
{
    
    [AifCollectionTypeAttribute('return',Types::Class,classStr(GITSWorkerList)),SysEntryPointAttribute(true)]
    public list PublicWorker(DataAreaId _company)
    {
        
        List WorkerList = new List(Types::Class);
        GITSWorkerList              GITSWorkerList;
        PurchRFQCaseTable           RFQCaseTable;
        DAP_Worker                  DAP_Worker;
        changeCompany(_company)
        {
            while select DAP_Worker
            {
                GITSWorkerList= new GITSWorkerList();
                GITSWorkerList.Name(DAP_Worker.Name);
                GITSWorkerList.Phone(DAP_Worker.Phone);
                GITSWorkerList.Address(DAP_Worker.Address);
                WorkerList.addEnd(GITSWorkerList);
            }
            return WorkerList;
        }
    }

}



Now create a service "GITSWorkerService"
Set the external name "GITSWorkerService"
And Description "Worker"
And class name property "GITSWorkerService"

[Note: Soap > XML]

Now create a service operation in the service and select the method as "PublicWorker" and the name of the operation as same

Now create a service group "GITSWorkerServiceGroup" and set auto-deploy property to "Yes"
Now create a service in the service group "GITSWorkerService" and set the service "GITSWorkerService"

Link to access the service
REST {JSON,XML}access: https://usnconeboxax1aos.cloud.onebox.dynamics.com/api/services/GITSWorkerServiceGroup/GITSWorkerService/PublicWorker
Note: OData also comes under REST services

Soap {Only XML}access: https://usnconeboxax1aos.cloud.onebox.dynamics.com/soap/services/GITSWorkerServiceGroup?wsdl