Using Azure Virtual Machines for Hosting WCF Services and Communicating with On Premises Applications

Abstract: Azure Virtual Machines are mighty useful to quickly setup and scale infrastructure. Today we’ll see how to create VMs in Azure and host a Sample WCF Service on it.

Windows Azure provides platform for enterprises to take their applications on the Cloud so that these applications can be available with less down time and less efforts for maintenance. One of the features available is to maintain Virtual Machines (VM) in the cloud. Today we’ll see how to create VMs in Azure and setup a Sample WCF Service on it.

Thanks to Mahesh Sabnis for setting up the VM’s and everything related to it

The Azure Management Portal and New Virtual Machines

We will see shortly how to create a new VM but as a quick snapshot, some of the pre-build VM options available are seen below:

You can create VMs for SQL Server, SharePoint 2013, BizTalk server etc. with Server Operating System like Windows Server 2008 R2 and Windows Server 2012. The advantage here is that you can have your VMs on the cloud and these will be available all the time for you. Once the VM is created, you can manage it by installing software like Visual Studio, etc. These VMs can be managed using Remote Desktop. The portal provides VM management like, Connect, Start Shutdown etc. as below:

Lets’ see how to Create Sql Server VM and host WCF service on the IIS of the VM

Step 1: Open the Windows Azure Portal www.windowsazure.com. Log in using your Live Credentials. You must have an active Windows Azure subscription for using AZURE services. You can get a 3 Months free trial as well.

Step 2: Once you have the subscription, you can create Azure Service, VM and Database etc.

In the Management Portal, select “Virtual Machines” and click on New Button on the bottom of the page as below:

You need to provide, the following information:

DNS Name: Is the unique name of the VM which is used for connectivity e.g. to the Database, IIS etc.

Size: Represents the VM size provided, Number of cores, Memory etc. The price varies according to the Size you selected. The sizes are as below:

User Name and Password: Required for the Administration of the VM.

The Location provides the datacenter for the VM.

Step 3: Once you enter all the necessary information, the VM will be created. Wait for its status to be in the Running State:

Once up and running can click on the VM name, to get the following page:

Click on the Endpoints tab to add endpoints. These endpoints are to communicate with the VM from outside Azure. We need to define endpoints so that Database and IIS on VM can be accessible to our on premises applications; so from the EndPoint page, click on Add EndPoint from the bottom and you will see the following page:

Click on the New arrow and on the next window, enter the information as shown below:

Make sure that we define only those endpoints which are required by your application. To access the IIS on the VM, you need to add Port 80. Also for accessing SQL server, add the Private port 1433.

Step 4: Once you add the necessary Endpoints, come back to Virtual Machines Page and click on the ‘Connect’ button on the bottom of the Page. You will get a ‘rdp’ file for downloading for the Remote Desktop of the VM. You need to connect to the VM by entering the Administration credential which are specified while creating VM.

Once the VM is created, you can get its communication details Dashboard page like DNS name, IP address etc. as shown below:

Step 5: Once you have the access to the VM, you can install IIS from the server Manager of the Server OS. Once you install IIS, you can access it from the on premises machine using the browser as shown below:

Step 6: To configure SQL Server on the VM for accessing on TCP protocol, go to the ‘Sql Server Configuration Manager’ on VM and select SQL Server Network Configuration and make sure that TCP, Named Pipe are enabled. Also from the Firewall of the VM, add a new Rule for accessing PORT 1433 of SQL Server.

Step 7: Open SQL Server on the VM and create a new Database of the name Company and the Table as EmployeeInfo as shown below:

To make this database accessible from your on premises application and SQL Server Management Studio, configure the database for Mix-Mode authentication as shown below:

Step 8: To access this database from your on-premises machine, open SQL Server Management Studio on your machine and set the Server Name to the DNS name, with the Public Port defined for SQL server and Authentication as Sql Server authentication:

Now you will get access to the Company database and you can now work with the EmployeeInfo Table.

Step 9: Open VS 2012 on your machine and create a new WCF Service Application. Use ADO.NET EF to connect to the Database on the VM for creating Entities. Write your logic for getting data from the Company Database > EmployeeInfo table. Build the WCF Service.

Step 10: To publish it on IIS in the VM, right click on the WCF Service and select ‘Publish’, Create a new profile for Publish and click on next. In the next window specify the Server name (DNS name), the site name (e.g. Default Web Site () the default port is 80), the user name and password of the remote server as shown below:

Now click on Next and Publish. Visual Studio will show the Publish status in the output window as shown below:

Step 11: Open a Browser on your machine and enter the address of your VM DNS followed by the WebSite where you have deployed the WCF service:

http:/xxxxxxx.cloudapp.net/Service.svc

Here you will see the following page:

Cool! You have deployed your service to a Virtual Machine in Azure.

Conclusion

Azure Virtual Machines are mighty useful to quickly setup and scale infrastructure in the short term where in-house procurement processes may introduce undesirable delays. Azure VMs as we saw, come in multiple software and hardware configurations. This really reduces the setup time as well as hardware and space requirements for VMs/Servers on premises.

Was this article worth reading? Share it with fellow developers too. Thanks!

Suprotim has received the prestigous Microsoft MVP award for nine times in a row now. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that represents premium web sites and digital publications comprising of Professional web, windows, mobile and cloud developers, technical managers, and architects.

Nice Article ! I feel you can also mention https://manage.windowsazure.com/ as direct alternate shortcut instead www.windowsazure.com in Step 1..it saves 2-3 clicks,Just Sign-In and you are directly on dashboard

Comment posted by
Vikram Pendse
on Wednesday, June 5, 2013 3:01 AM

Nice Article ! I feel you can also mention https://manage.windowsazure.com/ as direct alternate shortcut instead www.windowsazure.com in Step 1..it saves 2-3 clicks,Just Sign-In and you are directly on dashboard