Skip to main content



No record found.

Dynamics 365 Community / Forums / Commerce forum / How to call HardwareSt...
Commerce forum

How to call HardwareStation extension from POS

Posted on by

I have HardwareStation for PDF printing, copied from RetailSDK example.  

In HardwareStation.Extension.Config.  I add assembly for new extensions and 3rd party library.  

<add source="assembly" value="FreeSpire.PDF" />
<add source="assembly" value="XXX.Commerce.HardwareStation.Extension.PDFPrinter" />
<add source="assembly" value="XXX.Commerce.HardwareStation.Extension.WindowsPrinter" />

In Controller as below

namespace XXX
namespace Commerce.HardwareStation.PDFPrinter
using System;
using System.Threading.Tasks;
using Microsoft.Dynamics.Commerce.HardwareStation;
using Microsoft.Dynamics.Commerce.Runtime.Hosting.Contracts;
using Spire.Pdf;

/// <summary>
/// PDF printer web API controller class.
/// </summary>
public class PDFPrinterController : IController
/// <summary>
/// Prints the content.
/// </summary>
/// <param name="printRequest">The print request.</param>
/// <exception cref="System.Web.Http.HttpResponseException">Exception thrown when an error occurs.</exception>
public Task<bool> Print(PrintPDFRequest printRequest)
ThrowIf.Null(printRequest, "printRequests");

byte[] receivedFile = Convert.FromBase64String(printRequest.EncodedBinary);

// Add here the code to send the PDF file to the printer.
PdfDocument pdf = new PdfDocument(receivedFile);
pdf.PrintSettings.PrinterName = printRequest.DeviceName;

return Task.FromResult(true);
catch (PeripheralException ex)
catch (Exception ex)
throw new PeripheralException(PeripheralException.PrinterError, ex.Message, ex);

In POS Web AppBar extension, I call the HardwareStationRequest as in red text:

protected execute(): void {

this.isProcessing = true;
window.setTimeout((): void => {
this.isProcessing = false;
}, 2000);

let pdfTransferOrders = this.getTransferOrderPDF(this._order.orderId, this.transferDataAreaId, this.hardwareProfileId);

pdfTransferOrders.then((response: Commerce.Proxy.Entities.Receipt[]):
Promise<ClientEntities.ICancelableDataResult<PrinterPrintResponse>> => {
let receipts: ProxyEntities.Receipt[] = response;

// Prints the receipts.
//let printerPrintRequest: PrinterPrintRequest<PrinterPrintResponse> = new PrinterPrintRequest(receipts);

//return this.context.runtime.executeAsync(printerPrintRequest);

let receipt: Commerce.Proxy.Entities.Receipt = Commerce.ArrayExtensions.firstOrUndefined(
(p): boolean => { return Commerce.ArrayExtensions.hasElements(p.Printers) }

let printRequest: PrintPDFRequest = new PrintPDFRequest(receipt.Header, receipt.Printers[0].Name);

let hwsRequest: Commerce.HardwareStationDeviceActionRequest<Commerce.HardwareStationDeviceActionResponse>
= new Commerce.HardwareStationDeviceActionRequest<Commerce.HardwareStationDeviceActionResponse>(
"PDFPrinterController", // controller's name
"Print", // method name

return this.context.runtime.executeAsync(hwsRequest)
.then((hwsResponse: ClientEntities.ICancelableDataResult<Commerce.HardwareStationDeviceActionResponse>)
: ClientEntities.ICancelableDataResult<PrintPackingSlipClientResponse> => {
this.isProcessing = false;
return <ClientEntities.ICancelableDataResult<PrintPackingSlipClientResponse>>{ canceled: hwsResponse.canceled };

}).then((): Promise<void> => {
// Resolves to a void result when fulfilled.
this.isProcessing = false;
return Promise.resolve();
}).catch((reason: any): Promise<void> => {
// Resolves to a void result when rejected. This matches existing POS printing behavior.
this.context.logger.logError("Print transfer order execute error: " + JSON.stringify(reason));
this.isProcessing = false;
return Promise.resolve();


But once I run MPOS and click the AppBar button, I got error.  

The description for Event ID 46802 from source Microsoft-Dynamics-Commerce-ModernPos cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event:

["{\"number\":0,\"description\":\"\",\"stack\":\"CommerceError\\n at Error (ms-appx://microsoft.dynamics.retail.pos/Commerce.AsyncResult.js:29:21)\\n at HardwareStationRequestHandler.prototype._validateHardwareStationRequestUri (ms-appx://microsoft.dynamics.retail.pos/Pos.Core.js:56004:25)\\n at Anonymous function (ms-appx://microsoft.dynamics.retail.pos/Pos.Core.js:55965:25)\\n at Anonymous function (ms-appx://microsoft.dynamics.retail.pos/Pos.Framework.js:178:25)\",\"name\":\"CommerceError\",\"_canRetry\":false,\"_errorCode\":\"string_4908\",\"_externalLocalizedErrorMessage\":\"\",\"_handled\":false,\"_formatData\":[],\"_errorTitleResourceId\":\"\",\"_isUserError\":false,\"message\":\"\",\"ErrorCode\":\"string_4908\",\"ExternalLocalizedErrorMessage\":\"\",\"formatData\":[],\"errorTitleResourceId\":\"\",\"canRetry\":false,\"handled\":false,\"isUserError\":false,\"__proto__\":{}}"]

The publisher has been disabled and its resource is not available. This usually occurs when the publisher is in the process of being uninstalled or upgraded




I check in folder C:\Program Files (x86)\Microsoft Dynamics 365\70\Retail Modern POS\ClientBroker, those HardwareStation extension files are there already.   

Is it correct code for calling HardwareStation extension from POS?   

  • OriolMachin Profile Picture
    OriolMachin on at
    RE: How to call HardwareStation extension from POS

    Hello AyePKA,

    I corrected a typo on my earlier post, it was meant to say "Could you confirm if you are PAIRED TO theHardwareStation?"

    I'm very sorry for your experience. I'm not too familiar with the Support Plans, However I do see there are topics related to development and customizations.

    I'm hoping the community can contribute more to this topic, but if not, I believe the following two support topics should help with development issues.

    Selecting  Technical and System Administration > Development and customization:
    pastedimage1605642427292v1.png pastedimage1605642455659v2.png

    or I believe Commerce > Developer Experience


    I hope this helps,

    Oriol Machin

    Support Engineer / Microsoft Dynamics 365 Commerce

    North America Customer Services and Support

  • pka Profile Picture
    pka on at
    RE: How to call HardwareStation extension from POS

    I don't know if we have to pay for HardwareStation extensibility.

    Actually, my company has Technical support with ASfP Plan that will forward to China team (same timezone).   They always reject to help if it's about extensibility.    They mention "Out of scope".

  • OriolMachin Profile Picture
    OriolMachin on at
    RE: How to call HardwareStation extension from POS

    Hello AeyPKA,

    Could you please confirm if you are paired to the HardwareStation?

    if you will not get any advice from the community, please create a support ticket for us so we can investigate it further.

    Thank you for using Microsoft Dynamics 365 Communities,

    Oriol Machin

    Support Engineer / Microsoft Dynamics 365 Commerce

    North America Customer Services and Support

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,914 Super User

Martin Dráb Profile Picture

Martin Dráb 225,549 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans