VintaSoft Barcode .NET SDK v12.0 for .NET Core
In This Topic
    Read barcodes in ASP.NET Core MVC
    In This Topic

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

    1. Asynchronous barcode recognition

    The process of asynchronous barcode recognition can be divided into the following steps:
    1. Client-side: ASP.NET Core application sends an asynchronous request to a web service
    2. Server-side: The web service recognizes barcodes and sends the results to the application
    3. Client-side: The application processes the barcode recognition results

    Client-side of ASP.NET Core MVC application

    The WebBarcodeReaderJS class, from Vintasoft.Barcode.js file, can be used on a client-side of ASP.NET Core MVC application for barcode recognition.
    The WebBarcodeReaderJS 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 recognize Code39 barcodes from image:
    // create service that allows to write barcode
    var barcodeService = new Vintasoft.Shared.WebServiceControllerJS("/vintasoft/api/Barcode/");
    
    // create the barcode reader
    var barcodeReader = new Vintasoft.Barcode.WebBarcodeReaderJS(barcodeService);
    // specify that Code39 barcode must be searched
    barcodeReader.get_Settings().set_BarcodeType(new Vintasoft.WebBarcodeTypeEnumJS("Code39"));
    
    // create web image, where barcodes must be recognized
    var source = new Vintasoft.Shared.WebUrlImageSourceJS("/UploadedImageFiles/AllSupportedBarcodes.png");
    var image = new Vintasoft.Shared.WebImageJS(source, 0);
    
    // send an asynchronous request for barcode recognition
    barcodeReader.readBarcodes(image, __readBarcodes_success, __readBarcodes_fail);
    
    
    // Barcodes are recognized successfully.
    function __readBarcodes_success(data) {
        if (data.success) {
            // parse the barcode recognition result
        }
        else {
            alert(data.errorMessage);
        }
    }
    
    // Barcode recognition is failed.
    function __readBarcodes_fail(data) {
        // show information about error
        alert(data.responseJSON.ExceptionMessage);
    }
            
    


    Example: Here is JavaScript example that demonstrates how to recognize Code39, Code128, EAN13 and UPCA barcodes from image and obtain the results of print quality tests for all recognized barcodes:
    // create service that allows to recognize barcodes
    var barcodeService = new Vintasoft.Shared.WebServiceControllerJS("/vintasoft/api/Barcode/");
    
    // create the barcode reader
    var barcodeReader = new Vintasoft.Barcode.WebBarcodeReaderJS(barcodeService);
    // specify that Code39, Code128, EAN13 and UPCA barcode must be searched
    var barcodeTypesToSearch = new Vintasoft.Barcode.WebBarcodeTypeEnumJS("Code39");
    barcodeTypesToSearch = barcodeTypesToSearch.add("Code128");
    barcodeTypesToSearch = barcodeTypesToSearch.add("EAN13");
    barcodeTypesToSearch = barcodeTypesToSearch.add("UPCA");
    barcodeReader.get_Settings().set_BarcodeType(barcodeTypesToSearch);
    // specify that the print quality test information must be collected for all recognized barcodes
    barcodeReader.get_Settings().set_CollectTestInformation(true);
    
    // create web image, where barcodes must be recognized
    var source = new Vintasoft.Shared.WebUrlImageSourceJS("/UploadedImageFiles/AllSupportedBarcodes.png");
    var image = new Vintasoft.Shared.WebImageJS(source, 0);
    
    // send an asynchronous request for barcode recognition
    barcodeReader.readBarcodes(image, __readBarcodes_success, __readBarcodes_fail);
    
    
    // Barcodes are recognized successfully.
    function __readBarcodes_success(data) {
        if (data.success) {
            // parse the barcode recognition result
        }
        else {
            alert(data.errorMessage);
        }
    }
    
    // Barcode recognition is failed.
    function __readBarcodes_fail(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 recognition in ASP.NET Core.
    Important: Vintasoft.Barcode.dll, Vintasoft.Shared.dll, 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 Core MVC application create ASP.NET Core 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) contains the BarcodeReaderDemo, which demonstrates how to implement an asynchronous barcode recognition in ASP.NET Core MVC.