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 fabric and consume in a console application.
Follow the steps given below to create or add WCF Service web role in windows azure:
· Open Microsoft Visual Studio 2010 as an administrator.
· To create a new project File – New – Project.
· Select Cloud template from the Installed Templates.
· Select Windows Azure Project and enter the name of the project as WCFWebRole.
· Click OK to proceed.
· 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.
After adding WCF service, modify IService1.cs as given below:
public interface IService1
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:
Modify web.config file of WCF as shown below:
<transport clientCredentialType="Windows" />
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
After modifying the above files, press F5 to debug and run your application:
url of service (http://127.0.0.14:81/Service1.svc). The output should something like below:
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:
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.
When the service is successfully added in the application, add the service reference namespace:
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);
Now test the application by running (Ctrl + F5) your application:
After reading this article you can easily create WCF Service web role in windows azure application.