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

Posted by: Suprotim Agarwal , on 5/29/2013, in Category Microsoft Azure
Views: 40875
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:

list-of-available-vm

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:

capture

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:

newvm

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.

Image: Represents the type of the VM with the OS and other software installed e.g. Windows Server 2008 R1/ Windows Server 2012 with Sql Server, SharePoint 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:

vmsize

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:

status

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

endpoints

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:

  endpoint-azure-virtual

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

azure-endpoint-details

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:

vm-endpoint-details

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:

iis-access

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:

Create database Company
GO
USE [Company]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[EmployeeInfo](
    [EmpNo] [int] IDENTITY(1,1) NOT NULL,
    [EmpName] [varchar](50) NOT NULL,
    [Salary] [decimal](18, 0) NOT NULL,
    [DeptName] [varchar](50) NOT NULL,
    [Designation] [varchar](50) NOT NULL,
CONSTRAINT [PK_EmployeeInfo] PRIMARY KEY CLUSTERED
(
    [EmpNo] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

Add some test data in this table.

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:

sqlconfig

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:

sqlconnect

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:

publish-1

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

publish-2

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:

image

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.

This article has been editorially reviewed by Suprotim Agarwal.

Absolutely Awesome Book on C# and .NET

C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.

We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).

Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.

Click here to Explore the Table of Contents or Download Sample Chapters!

What Others Are Reading!
Was this article worth reading? Share it with fellow developers too. Thanks!
Share on LinkedIn
Share on Google+

Author
Suprotim Agarwal, MCSD, MCAD, MCDBA, MCSE, is the founder of DotNetCurry, DNC Magazine for Developers, SQLServerCurry and DevCurry. He has also authored a couple of books 51 Recipes using jQuery with ASP.NET Controls and The Absolutely Awesome jQuery CookBook.

Suprotim has received the prestigious Microsoft MVP award for Sixteen consecutive years. In a professional capacity, he is the CEO of A2Z Knowledge Visuals Pvt Ltd, a digital group that offers Digital Marketing and Branding services to businesses, both in a start-up and enterprise environment.

Get in touch with him on Twitter @suprotimagarwal or at LinkedIn



Page copy protected against web site content infringement 	by Copyscape




Feedback - Leave us some adulation, criticism and everything in between!
Comment posted by Vikram Pendse on Wednesday, June 5, 2013 2:20 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
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
Comment posted by Suprotim Agarwal on Wednesday, June 5, 2013 1:04 PM
@Vikram Thanks for that tip!