Demo Script Windows Azure Service Bus NetTcpRelayBinding Hybrid mode Version: 2.0.0 Last updated: 3/23/2016 Contents OVERVIEW ................................................................................................................................................... 3 Key Messages ........................................................................................................................................... 3 Key Technologies ...................................................................................................................................... 3 Time Estimates ......................................................................................................................................... 4 SETUP AND CONFIGURATION .................................................................................................................. 4 Task 1 – Creating a Service Bus Namespace ......................................................................................... 4 Task 2 – Opening the Direct Connection Sample.................................................................................. 4 DEMO FLOW ................................................................................................................................................ 5 OPENING STATEMENT............................................................................................................................... 6 STEP-BY-STEP WALKTHROUGH .............................................................................................................. 6 Looking at the code in Visual Studio ......................................................................................................... 6 Run the code ............................................................................................................................................. 8 SUMMARY .................................................................................................................................................... 9 KNOWN ISSUES ........................................................................................................................................ 10 Overview This demo shows the Service Bus NetTcpRelayBinding using Hybrid connection mode. When this works correctly, a direct connection is established between the client and service and the Service Bus is bypassed, increasing throughput. The code is part of the Windows Azure SDK samples that you can download from http://code.msdn.microsoft.com/windowsazure. Note: In order to run through this complete demo, you must have network connectivity and a Service Bus namespace. Key Messages 1. It is very simple for a .NET developer to modify a typical WCF app to use the .NET Service Bus 2. This binding gives you the highest performance and throughput and hybrid mode enables direct connections. Key Technologies This demo uses the following technologies: 1. .NET Framework 3.5 SP1 2. Visual Studio 2010 3. Windows Azure Libraries for .NET 4. Windows Azure Service Bus (i.e. internet connectivity is required) Time Estimates Estimated time for setting up and configuring the demo: 5 min Estimated time to complete the demo: 5 min Setup and Configuration This demo does not have any advanced configuration requirements. Make sure you have checked all the dependencies for this demo and have a Windows Azure account. For more information on how to purchase an account, visit the Windows Azure Portal at https://windows.azure.com/. Task 1 – Creating a Service Bus Namespace 1. Navigate to the Windows Azure Management Portal. You will be prompted for your Windows Live ID credentials if you are not already signed in. 2. Click Service Bus, Access Control & Caching link in the left pane, and then select “Service Bus” item under Services element. 3. Create a Service Namespace. Task 2 – Opening the Direct Connection Sample 1. Download the Relayed Messaging Bindings: NetTcp Direct from http://code.msdn.microsoft.com/Relayed-Messaging-Bindingsca039161. 2. Open Visual Studio running as administrator. Open the DirectConnnectionSample solution located in the zip file downloaded in the previous step. 3. Test the direct connection where you’re located to see if it works so that you’re not surprised when you run it in front of an audience. Demo Flow The following diagram illustrates the high-level flow for this demo and the steps involved: Figure 1 Diagram Opening Statement This demo shows how it’s possible to establish a direct connection between client and service using the Service Bus, even if they’re behind firewalls and NATs. Step-by-Step Walkthrough This demo is composed of the following segments: 1. Show the code in Visual Studio 2. Run the code Looking at the code in Visual Studio Action Script 1. Open the DirectConnectionSample in Visual Studio 2. Open the (service) HelloContract.cs This is the service contract. It’s a simple one-way contract with some text being sent from the client to the service. Screenshot 3. Open HelloService.cs Here is the service implementation – it does not do anything! 4. Open the service App.config In the App.config you can see we are using the netTcpRelayBinding and the connectionMode is set to “Hybrid". This means that we’ll try to establish a direct connection but if it’s not possible we’ll continue to communicate via the ServiceBus. The other connection mode is: Relayed – go through the bus 5. Open service Program.cs In the main program we have the standard code for creating a host. We’re using a “sb://”-based URI and username and password authentication. 6. Open client App.config The client is set up the same way, to use “Hybrid” mode with netTcpRelayBinding 7. Open client Program.cs The client app sends messages in a tight loop and every 250 milliseconds reports how many messages were sent in that time. 8. Show the ConnectionStateChanged event handler. There is a ConnectionStateChanged event raised when the connection state changes. In our case, if we go from relayed to direct we’ll get an “Upgraded!” message in the console window. Run the code Action Script 9. Right click Service in the Solution Explorer and select Debug > Start new instance 10. Enter the Service Namespace, 11. Entre the issuer name and key. Now we’ll run the application. First the service… Screenshot 12. Right click Client in the Solution Explorer and select Debug > Start new instance And now the client… You can see the number of messages sent by the client every quarter of a second. Now you can see the throughput has increased as a direct connection has been established. The Service Bus is no longer being used. 13. Enter the Service Namespace 14. Enter the issuer name and key 15. Make both console windows visible 16. [When the rate increases] Summary This demo showed how clients and services can connect via the Service Bus through firewalls and NATs, and then “upgrade” the connection to a direct connection by predicting the NAT port allocation. This mode offers much greater throughput and as messages do not go through the Service Bus there is no throughput charge. Known Issues Please note the following known issues with this demo: Test well before using. The busier the network you’re on, the less likely it is to work. Of course, if network bandwidth is the limiting factor rather than going via the Service Bus then you won’t see an increase in throughput.