---
title: "Creating WCF Service Web Role in Windows Azure Application"  
description: "In this article I am going to explain how to create WCF Service Web role in windows azure application and how to use the WCF Service in an outside app"  
author: "Chris Anderson"  
published: 2012-01-23  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/860/creating-wcf-service-web-role-in-windows-azure-application  
category: "cloud computing"  
tags: ["cloud computing"]  
reading_time: 3 minutes  

---

# Creating WCF Service Web Role in Windows Azure Application

In this article I am going to explain how to create WCF Service Web role in windows azure application and how to use the WCF Service in an outside application.

WCF Service Role enables us to create WCF service and host in Windows Azure. In this article, we will create a WCF Service Role and host on local [development](https://yourviews.mindstick.com/view/83465/china-s-development-near-indian-border-and-how-it-is-a-threat-to-india) fabric and consume in a [console application](https://www.mindstick.com/forum/160510/how-to-fetch-data-from-the-database-in-the-dot-net-console-application-using-c-sharp).

Follow the steps given below to create or add WCF Service web role in windows azure:

· Open [Microsoft](https://yourviews.mindstick.com/view/81711/microsoft-disconnects-cortana-and-reinvents-it) [Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) 2010 as an administrator.

· To create a new [project](https://yourviews.mindstick.com/story/1788/things-to-ensure-your-construction-project-is-successful) **File** – **New** – **Project**.

· Select **Cloud** [template](https://www.mindstick.com/blog/282/creating-custom-template-in-joomla) from the **Installed [Templates](https://www.mindstick.com/interview/34049/what-are-templates-in-knockout-js)**.

· Select **Windows Azure Project** and enter the name of the project as **WCFWebRole**.

· Click OK to proceed.

![Creating WCF Service Web Role in Windows Azure Application](https://www.mindstick.com/mindstickarticle/6ff6dab2-536a-4e14-b679-5d80a90a29e1/images/ec67813f-f94b-49fb-b71e-31e873fc1caa.png)

· To add a WCF service web role to the solution, choose **WCF Service Web Role** and then choose the right arrow. The roles are displayed in the **Windows Azure solution** pane of the dialog box.

· Click OK to proceed.

![Creating WCF Service Web Role in Windows Azure Application](https://www.mindstick.com/mindstickarticle/6ff6dab2-536a-4e14-b679-5d80a90a29e1/images/c38db6e9-1562-462c-915a-0c6aefb07b4a.png)

After adding WCF service, modify IService1.cs as given below:

```
    [ServiceContract]    public interface IService1    {        [OperationContract]        string GetSquare(double num);    } 
```

Also modify Service1.svc.cs as shown below:

```
  public class Service1 : IService1    {        public string GetSquare(double num)        {            return string.Format("The square of a number is:
{0}", Math.Sqrt(num));        }
    }
```

Modify **[web.config](https://www.mindstick.com/forum/183/web-config-file)** file of WCF as shown below:

```
<system.serviceModel>    <behaviors>      <serviceBehaviors>        <behavior>          <serviceMetadata httpGetEnabled="true"/>          <serviceDebug includeExceptionDetailInFaults="false"/>        </behavior>      </serviceBehaviors>    </behaviors>    <bindings>      <basicHttpBinding>        <binding>          <security mode="TransportCredentialOnly">            <transport clientCredentialType="Windows" />          </security>        </binding>      </basicHttpBinding>    </bindings>    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /></system.serviceModel>
```

After modifying the above files, press F5 to debug and run [your application](https://answers.mindstick.com/qa/95487/how-do-you-troubleshoot-when-your-application-link-is-not-responding):

url of service (http://127.0.0.14:81/Service1.svc). The output should something like below:

![Creating WCF Service Web Role in Windows Azure Application](https://www.mindstick.com/mindstickarticle/6ff6dab2-536a-4e14-b679-5d80a90a29e1/images/63c41769-d670-4f62-b8a7-64d852310064.png)

Now create a Console application in order to test the WCF service. To create console application **Open Visual Studio** – **File** – **New** – **Project** – **Windows** – **Console Application**.

After the application is open, add service reference in an application as shown in the below figure:

![Creating WCF Service Web Role in Windows Azure Application](https://www.mindstick.com/mindstickarticle/6ff6dab2-536a-4e14-b679-5d80a90a29e1/images/7b608fb1-d5ad-47bf-9f42-8e4980f0d61e.png)

Enter the **WCF Service path** in the Address textbox and click on the **Go** button to display the services. When the service is successfully displayed click on OK button to add service in the application.

![Creating WCF Service Web Role in Windows Azure Application](https://www.mindstick.com/mindstickarticle/6ff6dab2-536a-4e14-b679-5d80a90a29e1/images/0346d4e9-b28b-4471-94d7-fb379f776797.png)

When the service is successfully added in the application, add the service reference namespace:

```
using ConsoleApplication1.ServiceReference1;
```

To call GetSquare() method of the WCF Service (Service1) write the below code:

```
static void Main(string[] args)        {            Service1Client proxy = new Service1Client();            var result = proxy.GetSquare(10);            Console.WriteLine(result);            Console.ReadKey(true);        }
```

Now test the application by running (Ctrl + F5) your application:

![Creating WCF Service Web Role in Windows Azure Application](https://www.mindstick.com/mindstickarticle/6ff6dab2-536a-4e14-b679-5d80a90a29e1/images/36e7e826-e5a6-4acc-83e1-10df66abd22e.png)

After reading this article you can easily create WCF Service web role in windows azure application.

---

Original Source: https://www.mindstick.com/articles/860/creating-wcf-service-web-role-in-windows-azure-application

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
