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.
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:
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:
Create database Company
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
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
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
SET ANSI_PADDING OFF
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:
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:
Here you will see the following page:
Cool! You have deployed your service to a Virtual Machine in Azure.
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.
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 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 eBook 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 .NET Standard and the upcoming C# 8.0 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 Purchase this eBook at a Discounted Price!