Training
Certification
Microsoft Certified: Dynamics 365: Finance and Operations Apps Developer Associate - Certifications
Implement and extend finance and operation apps in Microsoft Dynamics 365.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This article explains how you can extend Commerce Data Exchange (CDX) - Real-time service by adding extension methods to the RetailTransactionServiceEx class. Real-time Service enables clients to interact with Commerce functionality in real time. Finance and Operation databases and classes can’t be accessed directly from Retail server. You should access them through the CDX class extension using the finance and operations and Commerce Runtime extension.
To extend Commerce Data Exchange - Real-time Service, you create a new method in the RetailTransactionServiceEx class. This method must meet the following criteria:
Start Microsoft Visual Studio.
On the Dynamics 365 menu, select Model management > Create model.
In the Create model dialog box, enter the following details.
Select Next.
In the dialog box, select Create new package > Next, select Select referenced packages, and then in the list select the Application Suite and Application Platform checkboxes.
Select Next.
Select Finish.
In the New project dialog box, enter ContosoRetailTransactionServiceEx as the project name.
Select OK.
Right-click the project and select Add > New item. In the Add New Item window, select Class and enter the name of the class as ContosoRetailTransactionServiceSample.
To consume the CDX method in Commerce runtime (CRT) you must add the ExtensionOf attribute to your class, such as ExtensionOf(classStr(RetailTransactionServiceEx). This addition means that the class is extending from the RetailTransactionServiceEx.
In the code editor, add the following code.
[ExtensionOf(classStr(RetailTransactionServiceEx))]
final class ContosoRetailTransactionServiceSample
{
}
Inside the class, add a new method to do your custom logic. This method is what you will call from CRT to do the custom logic.
[ExtensionOf(classStr(RetailTransactionServiceEx))]
final class ContosoRetailTransactionServiceSample_Extension
{
public static container SerialCheck(str _serialNum)
{
boolean success = false;
str errorMessage;
int fromLine;
try
{
if (_serialNum)
{
ttsbegin;
// check whether the serial number exists
// Add your custom logic
errorMessage = "Serial number found";
ttscommit;
}
else
{
// Add your custom logic
success = false;
errorMessage = "Serial number not found";
}
}
catch (Exception::Error)
{
ttsAbort;
errorMessage = RetailTransactionServiceUtilities::getInfologMessages(fromLine);
}
// Return sanitized error code.
errorMessage = RetailTransactionServiceUtilities::getErrorCode(errorMessage);
return [success, errorMessage, "Custom values"];
}
}
In Solution Explorer, right-click the project, and then click Build.
After you've finished building your new extension methods, the project will be deployed.
In your commerce runtime (CRT) extension, include the Microsoft.Dynamics.Commerce.Runtime.RealtimeServices.Messages nuget package, if it hasn't already been added.
Use the following sample code to call the new method.
InvokeExtensionMethodRealtimeRequest extensionRequest = new InvokeExtensionMethodRealtimeRequest("SerialCheck", "123");
InvokeExtensionMethodRealtimeResponse response = await request.RequestContext.ExecuteAsync<InvokeExtensionMethodRealtimeResponse> (extensionRequest).ConfigureAwait(false);
ReadOnlyCollection<object> results = response.Result;
string resValue = (string)results[0];
From the results object, you can read the response values from Real-time Service.
The CRT framework code will check the success/failure state and provide an error message based on the values returned from the CDX methods. If required, the extension code can catch this and provide more logic.
Note
The InvokeExtensionMethodRealtimeRequest method takes two parameters. One parameter is the Real-time Service method name, and the other is the list of parameters that should be used. The method name that is passed should be the same as the method name that you created in the ContosoRetailTransactionServiceSample class.
public InvokeExtensionMethodRealtimeRequest(string methodName, params object[] parameters)
: base(methodName, parameters)
{
}
When there is no connectivity to the HQ, client/Retail Server will not be able to call the CDX method. In this case, the extension code should follow the best practice mentioned below:
POS
Use the GetConnectionStatusClientRequest POS API.
CRT
if(request.RequestContext.Runtime.Configuration.IsMasterDatabaseConnectionString)
{ }
Training
Certification
Microsoft Certified: Dynamics 365: Finance and Operations Apps Developer Associate - Certifications
Implement and extend finance and operation apps in Microsoft Dynamics 365.