Kann ich IronBarcode for .NET auf Azure ausführen?
Ja! IronBarcode kann verwendet werden, um QR-/Barcodes in .NET-Anwendungen zu lesen und zu schreiben, die auf Azure-Diensten gehostet werden. IronBarcode wurde auf mehreren Azure-Plattformen, einschließlich MVC-Websites, Azure Functions und vielen mehr, gründlich getestet.
Voraussetzungen
1. Installation von IronBarcode zum Einstieg
Zuerst installieren Sie das NuGet-Paket auf der NuGet-Website.
Alternativ könnte die IronBarcode.dll auch heruntergeladen und Ihrem Projekt hinzugefügt werden.
Anleitung zum Tutorial
2. Leistung und Azure-Tarife
Wir empfehlen, mindestens den Azure B1 Serviceplan zu verwenden, da er für die meisten Anwendungsfälle unserer Benutzer geeignet ist. Systeme, die eine höhere Durchsatzrate erfordern, benötigen einen höheren Serviceplan.
3. Auswahl des Frameworks
.NET Standard, Core und Framework Projekte sind alle kompatibel mit IronBarcode.
4. Docker auf Azure
Eine Möglichkeit, die Leistung und Stabilität von IronBarcode auf Azure zu steuern, ist die Verwendung von Docker. Um zu lernen, wie man IronBarcode mit Azure und Docker verwendet, schauen Sie sich dieses Tutorial an.
5. Offizielle Azure Function Unterstützung
IronBarcode unterstützt derzeit Azure Functions V3 und V4.
Beispiel für einen funktionierenden Azure Function Code
Getestet auf Azure Functions v3.3.1.0+. Hier ist ein Codebeispiel:
using System;
using System.Net;
using System.Net.Http;
using IronBarCode;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http.Headers;
public static class BarcodeFunction
{
// Azure Function triggered by HTTP request.
[FunctionName("barcode")]
public static HttpResponseMessage Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
// Set the license key for IronBarcode if needed.
IronBarCode.License.LicenseKey = "Key";
// Create a QR barcode from a string.
var myBarCode = BarcodeWriter.CreateBarcode("IronBarcode Test", BarcodeEncoding.QRCode);
// Prepare the HTTP response to return the barcode image.
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(myBarCode.ToJpegBinaryData())
};
// Set content headers for attachment and content type.
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = $"{DateTime.Now:yyyyMMddmm}.jpg"
};
response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
return response;
}
}Imports System
Imports System.Net
Imports System.Net.Http
Imports IronBarCode
Imports Microsoft.AspNetCore.Http
Imports Microsoft.Azure.WebJobs
Imports Microsoft.Azure.WebJobs.Extensions.Http
Imports Microsoft.Extensions.Logging
Imports System.Net.Http.Headers
Public Module BarcodeFunction
' Azure Function triggered by HTTP request.
<FunctionName("barcode")>
Public Function Run(
<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route := Nothing)> req As HttpRequest,
log As ILogger) As HttpResponseMessage
log.LogInformation("VB.NET HTTP trigger function processed a request.")
' Set the license key for IronBarcode if needed.
IronBarCode.License.LicenseKey = "Key"
' Create a QR barcode from a string.
Dim myBarCode = BarcodeWriter.CreateBarcode("IronBarcode Test", BarcodeEncoding.QRCode)
' Prepare the HTTP response to return the barcode image.
Dim response = New HttpResponseMessage(HttpStatusCode.OK) With {
.Content = New ByteArrayContent(myBarCode.ToJpegBinaryData())
}
' Set content headers for attachment and content type.
response.Content.Headers.ContentDisposition = New ContentDispositionHeaderValue("attachment") With {
.FileName = $"{DateTime.Now:yyyyMMddmm}.jpg"
}
response.Content.Headers.ContentType = New MediaTypeHeaderValue("image/jpeg")
Return response
End Function
End ModuleImports System
Imports System.Net
Imports System.Net.Http
Imports IronBarCode
Imports Microsoft.AspNetCore.Http
Imports Microsoft.Azure.WebJobs
Imports Microsoft.Azure.WebJobs.Extensions.Http
Imports Microsoft.Extensions.Logging
Imports System.Net.Http.Headers
Public Module BarcodeFunction
' Azure Function triggered by HTTP request.
<FunctionName("barcode")>
Public Function Run(
<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route := Nothing)> req As HttpRequest,
log As ILogger) As HttpResponseMessage
log.LogInformation("VB.NET HTTP trigger function processed a request.")
' Set the license key for IronBarcode if needed.
IronBarCode.License.LicenseKey = "Key"
' Create a QR barcode from a string.
Dim myBarCode = BarcodeWriter.CreateBarcode("IronBarcode Test", BarcodeEncoding.QRCode)
' Prepare the HTTP response to return the barcode image.
Dim response = New HttpResponseMessage(HttpStatusCode.OK) With {
.Content = New ByteArrayContent(myBarCode.ToJpegBinaryData())
}
' Set content headers for attachment and content type.
response.Content.Headers.ContentDisposition = New ContentDispositionHeaderValue("attachment") With {
.FileName = $"{DateTime.Now:yyyyMMddmm}.jpg"
}
response.Content.Headers.ContentType = New MediaTypeHeaderValue("image/jpeg")
Return response
End Function
End ModuleIn diesem Code:
- Wir definieren eine Azure Function mit dem Namen "barcode."
- Die Funktion wird durch eine HTTP-Anfrage ausgelöst und protokolliert eine Nachricht, wenn sie verarbeitet wird.
- Wir geben den Lizenzschlüssel für IronBarcode an (ersetzen Sie
"Key"durch Ihren tatsächlichen Lizenzschlüssel). - Ein QR-Code-Barcode wird mit
BarcodeWriter.CreateBarcodegeneriert. - Das Barcode-Bild wird in JPEG-Format konvertiert und in die HTTP-Antwort eingebunden.
- Der Antwortinhalt wird als herunterladbare Anlage mit dem aktuellen Datum und der Uhrzeit als Dateiname festgelegt.
- Der Antwortinhaltstyp wird auf "image/jpeg" eingestellt, um das Bildformat anzuzeigen.
Häufig gestellte Fragen
Kann IronBarcode mit .NET-Anwendungen auf Azure verwendet werden?
Ja, IronBarcode kann zum Lesen und Schreiben von QR-/Barcodes in .NET-Anwendungen verwendet werden, die auf Azure-Diensten wie MVC-Webseiten und Azure Functions gehostet werden.
Welcher Azure-Serviceplan wird für IronBarcode empfohlen?
Es wird empfohlen, mindestens den Azure B1-Serviceplan für die meisten Anwendungsfälle zu verwenden, wobei höhere Servicepläne für Systeme erforderlich sind, die mehr Durchsatz benötigen.
Welche .NET-Frameworks sind mit IronBarcode auf Azure kompatibel?
IronBarcode ist kompatibel mit .NET Standard, Core und Framework-Projekten, die auf Azure laufen.
Wie kann Docker mit IronBarcode auf Azure verwendet werden?
Die Verwendung von Docker auf Azure kann helfen, die Leistung und Stabilität bei der Bereitstellung von IronBarcode zu kontrollieren, und ein Tutorial ist zur Anleitung verfügbar.
Werden Azure Functions offiziell von IronBarcode unterstützt?
Ja, IronBarcode unterstützt Azure Functions V3 und V4, was die Integration von Barcode-Funktionalitäten in Azure serverless computing ermöglicht.
Wie wird ein Barcode in einer Azure Function mit IronBarcode generiert und verwendet?
In einer Azure-Funktion kann ein Barcode mit BarcodeWriter.CreateBarcode erzeugt und als Bilddatei in der HTTP-Antwort zurückgegeben werden.
Welcher Inhaltstyp wird für Barcodelbilder in Azure Functions mit IronBarcode festgelegt?
Der Inhaltstyp für Barcodelbilder ist auf 'image/jpeg' gesetzt, wenn sie in der HTTP-Antwort von einer Azure Function mit IronBarcode zurückgegeben werden.
Ist es notwendig, einen Lizenzschlüssel für die Verwendung von IronBarcode in Azure Functions festzulegen?
Ja, das Festlegen eines Lizenzschlüssels für IronBarcode ist in Azure Functions notwendig, um die Bibliothek zu aktivieren und alle Beschränkungen zu entfernen.
Welches Dateiformat wird für Barcodes verwendet, die von IronBarcode in Azure Functions generiert werden?
Barcodes, die von IronBarcode in Azure Functions generiert werden, werden für die HTTP-Antwort in das JPEG-Format konvertiert.
Wie werden Inhalts-Header für Barcodelbilder in Azure Functions mit IronBarcode festgelegt?
Inhalts-Header werden gesetzt, um das Barcodelbild als herunterladbaren Anhang zu definieren, wobei das aktuelle Datum und die Uhrzeit als Teil des Dateinamens verwendet werden.
Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender Handbücher.