Azure Service Bus - Relay

This article explains about Azure Service Bus - Relay which has two entities - Hybrid Connection and WCF Relay. We will also see WCF Relay in detail.

A relay is used to communicate between on-premises applications and the outside world application. We can expose on-premises service endpoints to the public so that the outside world can access on-premise services from anywhere. We can have more than one listener for a single on-premise service endpoint. The biggest advantage of using this is that we have no need to open any port or any kind of firewall configuration. It uses Azure's network security without exposing our on-premise application.

Before we start implementing WCF Relay, let's revise WCF once.

Key points of WCF

Azure Service Bus - Relay
  1. WCF Service exposes one or more endpoints
  2. An endpoint consists of ABC, i.e., Address, Binding, and Contract
  3. Address is a unique Uniform Resource Locator (URI) that identifies the location of the service. It defines the network address for sending and receiving the messages.
  4. Binding specifies which transport protocol to use, what message format and which any of the ws* protocols we want to use to a particular endpoint.
  5. Contract provides the additional details of the structuring contents of the various messages that will be used by the various operations exposed to the particular endpoints.

Now, let's see the step by step implementation,

  1. Create Relay Namespace
  2. Create WCF Relay
  3. Create WCF Service
  4. Host WCF Service
  5. WCF Client

Create Relay Namespace

Create WCF Relay

Here, we can see two entities, i.e., Hybrid Connections and WCF Relays. But we are going to create WCF Relay.

Azure Service Bus - Relay

Create WCF Service (Library)

Host WCF Service (Console Application)

WCF Client (Console Application)

We can find our WCF Client as listener under WCF Relays.

Azure Service Bus - Relay

For demo purposes, we have created all the applications under a single solution, but in the real world, we can put WCF Service and Client on two different servers and verify how an external application (WCFClient) uses on-premise service, i.e., WCF Service through Relay.

Download the complete sample code from here.