How to create ASP.NET Web Services using Barcode Professional to serve barcode images
Product Barcode Professional for ASP.NET
Neodynamic Barcode Professional 2.0 for ASP.NET or greater
Neodynamic Barcode Professional 2.0 for Windows Forms or greater
Microsoft .NET Framework (any version)
Microsoft Visual Studio .NET (any version)
Create ASP.NET Web Services that needs to serve barcode images, is easier than ever with Barcode Professional (for ASP.NET or for Windows Forms). Barcode Professional now includes a method that allows you to return a byte array of the generated barcode image - a byte array is the object needed to server images in a Web Service project.
In the following sample, we'll create an ASP.NET Web Service project that allows you to serve barcode Code 128 images.
Follow these steps
- Open your .NET development tool - such as Visual Studio .NET - and create a new ASP.NET Web Service project. Name it as BCWebSampleWS.
- Add a reference to the Neodynamic.WebControls.BarcodeProfessional.dll assembly if you're using Barcode Professional for ASP.NET or Neodynamic.WinControls.BarcodeProfessional.dll assembly if you're using Barcode Professional for Windows Forms. We're going to use Barcode Professional as a component library.
- Now, under the web service class (rename it to BarcodeProfessionalWS), write the following code. This code is the public Web method that our clients will have to invoke in order to get a barcode Code 128 image:
Public Function GetBarcodeCode128(ByVal valueToEncode As String) As Byte()
Dim bcp As BarcodeProfessional = New BarcodeProfessional
bcp.Symbology = Symbology.Code128
bcp.Code = valueToEncode
bcp.Text = "From Web Service!"
bcp.ForeColor = System.Drawing.Color.Red
[WebMethod,Description("Generates a Code 128 barcode image")]
public byte GetBarcodeCode128(string valueToEncode)
BarcodeProfessional bcp = new BarcodeProfessional();
bcp.Symbology = Symbology.Code128;
bcp.Code = valueToEncode;
bcp.Text = "From Web Service!";
bcp.ForeColor = System.Drawing.Color.Red;
That's it. We're ready to serve barcode images from our Web Service. Build the ASP.NET Web Service application, run it and play with it.
After click on Invoke button you'll get this:
Now, we're going to create a client to consume this Web Service. This client will be a Windows Forms Application.
Follow these steps
- Open your .NET development tool - such as Visual Studio .NET - and create a new Windows Application project.
- Onto the Windows form, drag & drop a TextBox control, a Button control, and a PictureBox control.
- Add a web reference to the Barcode Web Service created previously. Name it as BarcodeWS.
- Finally, write the following code in the Button1_Click event procedure:
Dim bcws As BarcodeWS.BarcodeProfessionalWS = New BarcodeWS.BarcodeProfessionalWS
Dim barcodeImage As Byte() = bcws.GetBarcodeCode128(textBox1.Text)
Dim bmp As Bitmap = CType(Bitmap.FromStream(New System.IO.MemoryStream(barcodeImage)), Bitmap)
pictureBox1.Image = bmp
BarcodeWS.BarcodeProfessionalWS bcws = new BarcodeWS.BarcodeProfessionalWS();
byte barcodeImage = bcws.GetBarcodeCode128(textBox1.Text);
Bitmap bmp = (Bitmap) Bitmap.FromStream(new System.IO.MemoryStream(barcodeImage));
pictureBox1.Image = bmp;
That's it. We're ready to consume barcode images from the Barcode Web Service. Build the application, run it and play with it.