VintaSoft Barcode .NET SDK v12.0 (Cross-platform edition)
In This Topic
    Get barcode image in ASP.NET Core MVC
    In This Topic

    All resource-intensive operations in ASP.NET Core MVC application are performed asynchronously, so the barcode generation should be also performed asynchronously.

    1. Asynchronous barcode generation

    The process of asynchronous barcode generation can be divided into the following steps:
    1. Client-side: ASP.NET Core MVC application sends an asynchronous request to a web service
    2. Server-side: The web service generates a barcode and sends the results to the application
    3. Client-side: The application receives response from the web service and processes the generated barcode

    Client-side of ASP.NET Core MVC application

    The WebBarcodeWriterJS class, from Vintasoft.Barcode.js file, can be used on a client-side of ASP.NET Core MVC application for generating of barcode image.
    The WebBarcodeWriterJS class allows to:
    Important: JQuery (version 1.11 or higher) and Vintasoft.Shared.js file are necessary for correct work of Vintasoft.Barcode.js file.

    Example: Here is JavaScript example that demonstrates how to generate an image of QR Code barcode:
    // create service that allows to write barcode
    var barcodeService = new Vintasoft.Shared.WebServiceControllerJS("/vintasoft/api/Barcode/");
    
    // create the barcode writer
    var barcodeWriter = new Vintasoft.Barcode.WebBarcodeWriterJS(barcodeService);
    // specify that QR barcode must be generated
    barcodeWriter.get_Settings().set_BarcodeType(new Vintasoft.Barcode.Web2DBarcodeTypeEnumJS("QR"));
    
    // send an asynchronous request for getting barcode image as Base64 string
    barcodeWriter.getBarcodeAsBase64Image(__writeBarcode_success, __writeBarcode_failed);
    
    
    // Barcode image is generated successfully.
    function __writeBarcode_success(data) {
        if (data.success) {
            var imageAsBase64string = data.barcode;
            document.getElementById("barcodeImage").src = imageAsBase64string;
        }
        else {
            alert(data.errorMessage);
        }
    }
    
    // Barcode generation is failed.
    function __writeBarcode_failed(data) {
        // show information about error
        alert(data.responseJSON.ExceptionMessage);
    }
            
    


    Server-side of ASP.NET Core MVC application

    The SDK provides the VintasoftBarcodeApiController class (from Vintasoft.Barcode.AspNetCore.ApiControllers.dll assembly), which allows to create the ASP.NET Core API controller for barcode generation in ASP.NET Core MVC.
    Important: Vintasoft.Barcode.dll, Vintasoft.Shared.dll and Vintasoft.Shared.Web.dll and Vintasoft.Barcode.Web.Services.dll assemblies are necessary for correct work of Vintasoft.Barcode.AspNetCore.ApiControllers.dll assembly.

    Here is a code snippet that demonstrates how in ASP.NET MVC 4 application create Web API controller:
    namespace AspNetCoreMvcBarcodeDemos.Controllers
    {
        // ASP.NET Core API controller that handles HTTP requests from clients and
        // allows to read barcodes from image generate barcode image.
        public class BarcodeController : Vintasoft.Barcode.AspNetCore.ApiControllers.VintasoftBarcodeApiController
        {
    
            public BarcodeController()
                : base()
            {
            }
    
        }
    }
                    
    


    2. Demo applications

    The AspNetCoreMvcBarcodeDemos project (can be found in distributive package of VintaSoft Barcode .NET SDK (Cross-platform edition)) contains the BarcodeWriterDemo, which demonstrates how to implement an asynchronous generation of barcode image using the web service based on ASP.NET Core API controller.