Home > Azure > On-Premises Cloud Integration

On-Premises Cloud Integration

I am working on a very interesting project which is a hybrid cloud application and runs on premises and in the cloud. The bulk of system is in the cloud with service bus orchestration and the Azure website however we have one windows service which runs on the client premise i.e. in client’s DMZ and polls for a specific FTP folder and then sends the message to the cloud service bus. If you are new to Azure Service Bus I recommend to read my previous post on Azure Service Bus.

One of the major gotcha was that our windows service when tested from our internal network was able to send the message to Azure Service Bus without any problem but when the service was deployed in the clients DMZ we were getting some problem related to net TCPIP binding. I was bit confused and decided to replicate the problem and then figure out what is going on under the hood.

So the exception was related to network socket exception and this is what the exception was.

Could not connect to net.tcp://prashantbrall.servicebus.windows.net:9354/. The connection attempt lasted for a time span of 00:00:00.0140062. TCP error code 10013: An attempt was made to access a socket in a way forbidden by its access permissions xx.xx.xx.127:9354.

First thing what I did was to create a firewall rule to block the port 9354 and see what happens, so I went to windows firewall advance properties and on outbound rule right clicked and select new rule and added the rule as shown below.

port block general properties

firewall port 9354 configuration

I name the rule with a prefix “—” so that it is always on the top of the firewall rule, otherwise it is hard to scroll through so many firewall rules to find out which one you just added.

Windows Firewall port 9354 added rule.

As soon as I did that and I tried sending a message to the Azure Service Bus and I got the same exception. So I figure out the port was blocked on the client’s DMZ and it would take a lot of effort/meeting and infrastructure change request to finally get the port open. So I decided that let’s use the code and try to use the HTTP binding rather than the TCPIP binding and apparently it was much easier than I thought, in fact it is just one line of code.

ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;

Just add this code before you create a QueueClient object and below is the complete code.


class Program
    const string QueueName = "OrderQueue";
    static void Main(string[] args)
            ServiceBusEnvironment.SystemConnectivity.Mode = 

            var queueClient = QueueClient.Create(QueueName);
            while (true)
                var message = queueClient.Peek();
                if (message != null)
                    var orderMessage = message.GetBody();
                    Console.WriteLine("Order with Id = {0} and Qty = {1} " + 
                            "has been received..",
        catch (Exception ex)
           Console.WriteLine(ex.Message + "\n" + ex.StackTrace);


    static void SendMessage(QueueClient queueClient)
        var newOrder = new OrderMessage
                OrderId = 123, Qty = 20

        queueClient.Send(new BrokeredMessage(newOrder));

Happy Azuring !!!

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: