BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News CoreWCF Gets Azure Storage Queue Bindings

CoreWCF Gets Azure Storage Queue Bindings

Microsoft released a CoreWCF service library and a WCF client library with the bindings for Azure Storage Queue. The new bindings allow developers to use Azure Service Queues for reliable and scalable messaging solutions. They also unlock simple migration of legacy Microsoft MSMQ WCF solutions to an Azure cloud-based architecture.

The Azure Storage Queue is a cloud-based queue service built on top of Azure Storage that allows any components to send, store and receive messages reliably and asynchronously.

It is worth clarifying that the Azure Storage Queue binding in CoreWCF, like the legacy MSMQ (Microsoft Message Queuing) binding, is a one-way operation, meaning the client gets no response for the service invoked via the binding. Consequently, only void methods are allowed in the CoreWCF service interface. The MSMQ support in CoreWCF remains in the preview stage, and it has been in development for over a year.

There are two packages for Azure Storage Queue support: one for the client scenario (sending messages to the queue) and one for the server scenario (reading the messages from the queue and processing them). The Azure Storage Queue client library and Azure Identity library are pulled together with the packages as a dependency. There is a sample of the usage of the new bindings on the Azure SDK for .NET GitHub account.

The bindings are released by the Azure SDK for .NET team and not by the CoreWCF team. Also, the client library is released as a .NET package compatible with the Windows-only .NET Framework WCF stack. The stated goal of the packages is to enable migrating existing WCF clients to .NET that are currently using MSMQ and wish to deploy their service to Azure, replacing MSMQ with Azure Queue Storage.

To call an Azure Storage Queue using CoreWCF or WCF, the developers must add Microsoft.WCF.Azure.StorageQueues prerelease NuGet package to their .NET project. The first step is to authenticate the client that is calling the Azure Storage Queue. The default mechanism is to leverage the DefaultAzureCredential provider using a parameterless constructor for AzureQueueStorageBinding. The queue address is passed to the CoreWCF’s regular ChannelFactory class to create a communication channel for the service that will be invoked.

// Create a binding instance to use Azure Queue Storage.
// The default client credential type is Default, which uses DefaultAzureCredential
var aqsBinding = new AzureQueueStorageBinding();

// Create a ChannelFactory to using the binding and endpoint address, open it, and create a channel
string queueEndpointString = "https://MYSTORAGEACCOUNT.queue.core.windows.net/QUEUENAME";
var factory = new ChannelFactory<IService>(aqsBinding, new EndpointAddress(queueEndpointString));
factory.Open();
IService channel = factory.CreateChannel();
channel.Open();

// Invoke the service
await channel.SendDataAsync(42);

To create a CoreWCF service that will be exposed as a consumer of the Azure Storage queue, developers have to use Microsoft.CoreWCF.Azure.StorageQueues prerelease NuGet package. The process of creating the service binding starts with adding the queue transport to the CoreWCF services collection in the service configuration step. In the app builder configuration step, the binding itself is constructed. Then, the service is connected to the queue using the AddServiceEndpoint method, passing the instantiated binding and specifying the queue address.

public class Startup
{
  public void ConfigureServices(IServiceCollection services)
  {
    services.AddServiceModelServices();
    services.AddQueueTransport();
  }

  public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  {
    app.UseServiceModel(services =>
      {
        serviceBuilder.AddService <Service>();
        var aqsBinding = new AzureQueueStorageBinding();
        string queueEndpointString = "https://MYSTORAGEACCOUNT.queue.core.windows.net/QUEUENAME";
        serviceBuilder.AddServiceEndpoint <Service, IService> (aqsBinding, queueEndpointString);
      });
  }
}

Although these examples use the default Azure authentication, the binding library allows for the use of either a storage shared key credential, a SAS (shared access signature), an OAuth token or an Azure Storage connection string. There is a Security.Transport.ClientCredentialType option in the AzureQueueStorageBinding class to specify these settings.

The CoreWCF project was officially released in April 2022, although it had already begun in 2019. It aims to provide a subset of the most frequently used functionality from WCF service on the .NET platform. It is .NET Standard 2.0 compatible, allowing it to be migrated in place on .NET Framework 4.6.2 or above. It covers HTTP and TCP transport protocols with mainstream WCF bindings and other protocols such as Kafka or RabbitMQ. The current version is 1.6.0.

The Azure Storage Queue binding support for CoreWCF comes almost a year after the AWS team released a similar package supporting AWS SQS (Simple Queue Service) queues.

About the Author

Rate this Article

Adoption
Style

BT