Clarity, Technology, and Solving Problems | PracticeThis.com
WP7 App with Key Windows Azure resources – Slides, Videos, How-To’s, and T-shooting – for quick consumption on the go.
This is index of available How-To’s for Windows Communication Foundation (WCF) distilled from the WCF Documentation available on MSDN. Topics covered:
Detailed list of How-To’s is below.
This is continuation to the series on how to build distributed application hosted in Windows Azure Environment and Security using Windows Azure AppFabric Access Control Service (ACS) v2. For previous parts review the following:
This is first part of the series on how to secure Windows Azure deployed WCF service using ACS v2.0. It assumes you have completed previous parts outlined above.
Content in this step is adopted, adapted, and extended based on Code Quick Start: Create and deploy a WCF service in Windows Azure and Code Quick Start: Create a client application that uses a WCF service deployed to Windows Azure
Switch back to Visual Studio 2010 make sure it runs with administrator privileges. To launch Visual Studio with administrator privileges, right-click Microsoft Visual Studio 2010 and then click Run as administrator.
Right click on your solution in the Solution Explorer and choose Add and then New Project... option.
Within the New Project dialog, navigate to Installed Templates, Visual C#, and click Cloud.
Click Windows Azure Project. If needed, modify the Name: and the Location: fields, which indicates where your solution will be stored. Click OK to close the New Project dialog.
Within the New Windows Azure Project dialog, navigate to Visual C#, click the WCF Service Web Role, and then click the > symbol. This will add a web role to your Windows Azure solution. A web role provides an environment for running web sites or applications as supported by Internet Information Services (IIS) 7.0. Click OK to close the New Windows Azure Project dialog.
Modify IService1.cs to contain one operation, ReverseString. To navigate to IService1.cs, open Solution Explorer. If Solution Explorer is not visible, from the View menu click Solution Explorer. Within Solution Explorer, expand WCFServiceWebRole1 and double-click IService1.cs. Modify the contents of IService1.cs to be the following code:
public interface IService1
string ReverseString(string stringToReverse);
Save and close IService1.cs.
Modify Service1.svc.cs to contain the implementation of the operation GetHello. (Use Solution Explorer to navigate to Service1.svc.cs similar to the way you navigated in the previous step.) Modify the contents of Service1.svc.cs to be the following code:
public class Service1 : IService1
public string ReverseString(string stringToReverse)
char chars = stringToReverse.ToCharArray(); Array.Reverse(chars); return new string(chars);
Save and close Service1.svc.cs.
Set the WCF project as a start up project by right clicking on it in Solution Explorer and choosing Set as StartUp Project option.
Set Service1.svc as a start page by right clicking on it and choosing Set As StartUp option.
Compile and run the service by clicking Debug from the menu and then clicking Start Without Debugging, or using Ctrl+F5.
You should see WCF Test Client start up.
Double click ReverseString() node on the left in the WCF Test Client. You should see Request and Response sections on the right.
In the Request section type Hello World! in the Value field in the row where stringToReverse appears under the Name field.
Click on Invoke button located between the Request and Response sections.
You should see "!dlroW olleH" shows in the Value field in the Response section.
Add a web service reference to your WCF service in ASP.NET web application. To add a web service reference, open Solution Explorer. If Solution Explorer is not visible, from the View menu click Solution Explorer. Within Solution Explorer, expand the nodes until you see References under your ASP.NET web application. Right-click References and click. Add service reference…. Within the Add Service Reference dialog, click on Discover button. It should list Service1 in the Services: section. Click on Advanced button. Ensure Always generate message contracts is checked in the Service Reference Settings dialog. Click OK to close the Service Reference Settings dialog. Click OK to close the Add Service Reference dialog.
Open Default.aspx.cs. To open Default.aspx.cs, navigate to Default.aspx in Solution Explorer and expand it. You should see now Default.aspx.cs, double click it. Modify the contents Page_Load to be the following code:
protected void Page_Load(object sender, EventArgs e)
ServiceReference1.Service1Client client = null;
client = new ServiceReference1.Service1Client();
ServiceReference1.ReverseStringRequest request = new ServiceReference1.ReverseStringRequest("Hellow World!");
response = client.ReverseString(request);
Response.Write(HttpUtility.HtmlEncode("The WCF service called returned: '" + response.ReverseStringResult + "'"));
catch (Exception ex)
Response.Write(HttpUtility.HtmlEncode("Exception encounter: '" + ex.Message + "'"));
if (null != client)
Save and close Default.asp.cs.
Set your ASP.NET web application as a start up project by right clicking on it in Solution Explorer and choosing Set As StartUp Project. The one that has Roles folder in it. It does not have actual web content in it.
Run the WCF service first by right clicking on it in Solution Explorer and choosing Debug and then Start new instance option. You should see WCF Test client appears. Do not close it.
Now run the ASP.NET application by right clicking on it and choosing Debug and then Start new instance option.
You should be presented with the page that offers you to choose Google or Windows Live ID as an options.
After successful authentication with either of these you should be presented with the Default.aspx page with the following line at the top: The WCF service called returned: '!dlroW wolleH'
CAVEATS: you will need to make couple of changes in both web.config and ACS v.2 management portal to make sure ACS v2.0 redirects you back to your development environment and not to the one already deployed to Windows Azure.
Can you quickly tell me what’s Windows Azure, what scenarios it fits and how to make it work in 30 minutes or less?