How to create ASP.NET Web Services using Barcode Professional to serve barcode images
Product Barcode Professional for ASP.NET Published 10/14/2006 Updated 10/14/2006
Requirements
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:
VB
_ 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 Return bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Gif) End Function C#
[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; return bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Gif); }
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:
VB
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 = bmpC#
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.
Need help? Contact Support
We provide best-in-class customer service and support directly from members of our dev team! If we are available when you contact us, you will get a response in few minutes; otherwise the maximum turnaround is 24hs in most cases.