VintaSoft Barcode .NET SDK v9.2
Read barcodes in ASP.NET WebForms

Barcode recognition in an ASP.NET WebForms application can be implemented synchronously or asynchronously. The modern web applications are functioning asynchronously because this allows to prevent blocking of the application UI, so the asynchronous barcode recognition is more preferable.

1. Asynchronous barcode recognition

The process of asynchronous barcode recognition can be divided into the following steps:
  1. Client-side: ASP.NET WebForms 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 WebForms application

The WebBarcodeReaderJS class, from Vintasoft.Barcode.js file, can be used on a client-side of ASP.NET WebForms 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 recognize barcodes
var barcodeService = new Vintasoft.Shared.WebServiceHandlerJS("/Handlers/Barcodes/BarcodeHandler.ashx");

// 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 write barcode
var barcodeService = new Vintasoft.Shared.WebServiceHandlerJS("/Handlers/Barcodes/BarcodeHandler.ashx");

// 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 WebForms application

Depending on application architecture the web service, which recognizes barcodes, can be based on WCF service or HTTP handler.
SDK provides the following ready-to-use web services:
Important: Vintasoft.Barcode.dll, Vintasoft.Shared.dll and Vintasoft.Shared.Web.dll assemblies are necessary for correct work of Vintasoft.Barcode.Web.WcfServices.dll or Vintasoft.Barcode.Web.HttpHandlers.dll assembly.

Here is a code snippet that demonstrates how in ASP.NET WebForms application create HTTP handler:
using Vintasoft.Barcode.Web.HttpHandlers;

namespace AspNetBarcodeDemos.Handlers.Barcodes
{
    // HTTP handler for reading and writing barcodes.
    public class BarcodeHandler : VintasoftBarcodeHandler
    {

        public BarcodeHandler()
            : base()
        {
        }

    }
}
                


2. Synchronous barcode recognition

The process of synchronous barcode recognition can be divided into the following steps:
  1. Client-side: ASP.NET application sends request to ASPX page
  2. Server-side: Page executes its server code, recognizes barcodes and sends new page layout to the application
  3. Client-side: The application receives the new ASPX page layout and refreshes the page

Usage of AJAX technology allows to refresh a part of page instead of the whole page.


3. Demo applications

The AspNetBarcodeDemos project (can be found in distributive package of VintaSoft Barcode .NET SDK) contains the BarcodeReaderDemo, which demonstrates how to implement an asynchronous recognition of barcodes using the web service based on HTTP handler.

Also the AspNetBarcodeDemos project contains the SyncBarcodeReaderDemo, which demonstrates how to implement a synchronous recognition of barcodes on ASPX page.