Click here to Skip to main content
15,179,476 members
Articles / Programming Languages / C#
Posted 31 Mar 2009


7 bookmarked

Getting WCF to Work with Azure

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
1 Apr 2009CPOL4 min read
Avoiding the WCF issue in the Azure CTP

Silverlight makes creating compelling Rich Internet Applications fairly easy. That said, the cut down version of .NET means some things that you would do within an application have to be relegated to Web Services which can benefit from the full .NET library. One of these is of course Azure, after all, that is the whole point - an online store of Business Logic and data.

The application I'm working on uses Silverlight on the front end, and Azure will provide the bulk of the backend. There are reasons for this; my budget for the site is not that large, adopting Azure means first off that it will be free during development, but almost as important - hosting costs will be related to the success of the site.

The thing is dealing with pre-beta software has meant an increase in grey hairs and those that are left are getting fewer. One of the parts that needs looking at is in WCF. If you run the Azure Labs, the WCF lab does not work. This is because the Development Fabric is not hosting the service correctly, and WCF metadata is not being returned correctly.

Thanks must go to David Burela and his House-o-blog. In it, he describes a way to get WCF working despite the problems with the Development Fabric. So what I thought I would do is write a version of the Azure Services Training Kits Exercise 3: Hosting a WCF Service

So the following is Exercise 3, but with the changes made to ensure it works.

  1. Open the project you created in Exercise 2 or open the begin.sln solution file located in C:\AzureServicesKit\Labs\BuildingWindowsAzureServices\Ex03-HostingWCFService\begin\.


    If you closed Visual Studio, be sure to open it elevated as Administrator, from Start | All Programs | Microsoft Visual Studio 2008 right-click Microsoft Visual Studio 2008 and choose Run as Administrator.

  2. Add the WCF service file. To do this, right-click the RDCompute_WebRole node in Solution Explorer, point to Add and select New Item. In the Add New Item dialog, select the WCF Service template, change the Name to MessageLogger.svc, and then click Add.

    Add New Item


    The template adds an IMessageLogger interface, which defines the service contract and a MessageLogger class that implements the contract.

  3. Update the contract interface to define a method to send messages to the service. Open the IMessageLogger.cs file in the text editor. This file contains the generated IMessageLogger interface, which includes a single method named DoWork. Delete this method, and insert a LogMessage method to replace it (shown highlighted in bold text below.)
    public interface IMessageLogger 
     void LogMessage(string message); 
  4. Implement the contract interface in the MessageLogger service. Open the MessageLogger.svc.cs file in the text editor. This file contains the service implementation and includes a skeleton DoWork method. Again, delete this method and insert the following code that implements the LogMessage method in its place.
    public void LogMessage(string message) 
  5. Change the binding of the IMessageLogger endpoint to use a basicHttpBinding. Open the Web.config file in the text editor and locate the RDCompute_WebRole.MessageLogger service configuration in the services section inside system.serviceModel. This should be towards the end of the file. Change the binding attribute of the single endpoint contained in this section from wsHttpBinding to basicHttpBinding. The endpoint configuration after the change should be as follows:
    <endpoint address="" binding="basicHttpBinding" 
        <dns value="localhost" />
  6. Right click on the ASP.NET project (AzureWCFDemo_WebRole) and set it as the startup project.
  7. Right click on the MessageLogger.svc file and select View in Browser.
  8. When Internet Explorer starts, copy the address displayed in the Address Bar to the clipboard.
  9. Start a new instance of Visual Studio.
  10. Create a console client project by selecting File, New Project.


  11. Add a reference to the message logging service. In Solution Explorer, right-click the MessageGenerator project node, and select Add Service Reference. Paste the address you copied from the Internet Explorer instance into the Add Service Reference dialog and click Discover. Change the Namespace to RDService and click OK.
  12. Add the following code to the main function:
    using (RDService.MessageLoggerClient client = new RDService.MessageLoggerClient())
        Console.WriteLine("Enter your messages ('quit' to exit)");
        while (true)
            string message = Console.ReadLine();
            if (message.Equals("quit", StringComparison.CurrentCultureIgnoreCase))
          catch (Exception ex)
  13. Return to the instance of Visual Studio running the ASP.NET application and stop debugging the ASP.NET application.
  14. Right click the Azure project and set as the Start-up project, then start debugging. The Dev Fabric should start running and hosting the WCF service. When Internet Explorer starts, note the port number. More than likely this will be 81.
  15. Finally, go back to our client project. Open the app.config file and change the endpoint address so that is the port number found in the previous step.
  16. Now run the client project. It should be able to call the WCF Service hosted within the Development Fabric.

    If everything worked, you should have completed Exercise 3. Hopefully, a fix to the problem will be forthcoming.

    Image 3


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Paul S. Chapman
Software Developer (Senior) Simplicita Online
United Kingdom United Kingdom
UK based IT Consultant. Started in 1985 selling home computers such as the Sinclair ZX Spectrum, BBC Model B and Commodore 64, and in 1987 moved into development, starting first with Torch Computers, developing software for the XXX UNIX Workstation.

Currently developing a new Azure/Silverlight based website/desktop applications for a new startup, hoping to launch in late 2009/early 2010

Comments and Discussions

GeneralFormatting Pin
Jeffrey Walton31-Mar-09 4:33
MemberJeffrey Walton31-Mar-09 4:33 
QuestionRe: Formatting Pin
Paul S. Chapman31-Mar-09 10:13
MemberPaul S. Chapman31-Mar-09 10:13 
AnswerRe: Formatting Pin
Jeffrey Walton31-Mar-09 11:09
MemberJeffrey Walton31-Mar-09 11:09 
GeneralRe: Formatting Pin
Paul S. Chapman31-Mar-09 12:02
MemberPaul S. Chapman31-Mar-09 12:02 
Found it!

CP did not eat the content. Have now edited the article so it should make sense, removed all the code paragraphs with nothing in!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.