Add New Function to Commerce Service

In this article

Sample MyCustomFunction

This sample describes how to add a new function to Commerce Service API Interface that can be called from a Mobile Loyalty App or from the eCommerce Web Site.

Open Source code for Commerce Service and Mobile Apps is stored in separate Git repositories.

The code can be joined together, if you are working with the Loyalty App, as the code in the Common folder is same in both solutions. For eCommerce, Loyalty App code is not needed.

  1. Open Server\WcfService\LSOmniService.sln
    (in some cases, you need to run Visual Studio as Admin to load Service Project)
  2. Set Service Project as StartUp Project.
  3. Set correct connection data into Service\AppSettings.config
  4. Set which DataAccess Project Commerce Service should run

    <add key="BOConnection.AssemblyName" value="LSOmni.DataAccess.BOConnection.CentralPre.dll"/>

Tip: You can get this data from an already installed and running Commerce Service.

Commerce Service uses these interfaces:

Json Interface SOAP Interface Usage
IBOJson IBOService LS Central to communicate back to Commerce Service
IUCJson IUCService Ecommerce and Loyalty API Interface

The main code blocks are:

Commons\Domain.DataModel.Base Common Data objects used by all apps and Web sites and common code used by the Common Data Object.
Commons\Domain.DataModel.Loyalty Common Loyalty Data objects.
DataAccess\BOConnection.PreCommon Web service communication against LS Central 17.5 and later.
DataAccess\BOConnection.NavCommon Web service communication againstLS Central 17.4 or older LS Nav.
DataAccess\BOConnection.CentralPre Data communication for LS Central 17.5 and later.
DataAccess\BOConnection.CentrAL Data communication for LS Central 15 to 17.4.
DataAccess\BOConnection.NavSQL Data communication for LS Central 14 and older LS Nav.
DataAccess\BOConnection.NavWS Web Data communication for LS Central in the cloud.
DataAccess\Data.SQLServer Local Commerce SQL Database communication.
DataAccess\Interfaces Interface files for DataAccess projects.
BusinessLayer Business Logic that takes care of loading correct DataAccess code and calls the function.
Service Commerce Service Interface code.

Tip: You can remove DataAccess projects that Commerce Service will not be using to make things easier while coding.

LS Central 14 or older LS Nav, running on-premises: you can remove projects CentralPre, CentrAL and NavWS.

LS Central 17.5 and later running on-premises: you can remove projects NavSQL, CentrAL and NavWS.

Sample MyCustomFunction

The most common code path is the following:

Commerce Service Interface calls the Business Layer, which loads the DataAccess code according to settings in the AppSettings.config file, and then calls the code in appropriated DataAcccess that gets the data from its source, either direct from database or web service.

In the Bitbucket code, there is already a sample of a new function, MyCustomFunction, which Web Sites and the Loyalty app can both use.
Tip: It is best to start from the end of the code path when adding a new function.

Depending on the LS Central version, your code should be placed in the appropriated DataAccess Project, see table above for which project to use. You can also remove the other projects that you will not be using.

The sample has code for LS Central 14, 15, and 18.

NavSQL project is used for LS Central 14 and earlier versions of LS Nav.

The main on-premises database processing code is located in the Dal folder.

The code that takes care of deciding if it should call web service or go directly into BC Database is NavCustom.cs.

This sample shows how to make a direct Database call and how to use LS Central Web Service call, but you would only use one of the methods.

The same applies to LS Central 15 to 17.4: you do the same as above, except it is done in CentrAL project (DataAccess\BOConnection.CentrAL).

For LS Central 17.5 and later, do the code in CentralPre project (DataAccess\BOConnection.CentralPre)

Interface for all DataAccess projects is added here:

Business Layer loads up the DataAccess DLL according to app settings and then calls the new function:

Commerce Public Interfaces call this code, which then calls the function in Business Layer. This is where the code flows begins when incoming calls come in.
Tip: You can put your break point here to catch the beginning of the code flow when doing debug.

Public interfaces

Testing MyCustomFunction

If all is in order, you get this answer:

Tip: SoapUI is a free tool that can be used to test the SOAP (service) interface. There you can find your new function and put in some data, run it, and get the result: