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.
- 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.
- 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.
The template adds an
IMessageLogger interface, which defines the service contract and a
MessageLogger class that implements the contract.
- 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);
- 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)
- 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
basicHttpBinding. The endpoint configuration after the change should be as follows:
<endpoint address="" binding="basicHttpBinding"
<dns value="localhost" />
- Right click on the ASP.NET project (
AzureWCFDemo_WebRole) and set it as the startup project.
- Right click on the MessageLogger.svc file and select View in Browser.
- When Internet Explorer starts, copy the address displayed in the Address Bar to the clipboard.
- Start a new instance of Visual Studio.
- Create a console client project by selecting File, New Project.
- 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.
- Add the following code to the main function:
using (RDService.MessageLoggerClient client = new RDService.MessageLoggerClient())
Console.WriteLine("Enter your messages ('quit' to exit)");
string message = Console.ReadLine();
if (message.Equals("quit", StringComparison.CurrentCultureIgnoreCase))
catch (Exception ex)
- Return to the instance of Visual Studio running the ASP.NET application and stop debugging the ASP.NET application.
- 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.
- 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.
- 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.