WCF services hosted on Windows Azure

I’ve gotten quite a few questions asking how to get WCF services working correctly under Windows Azure. There are 2 main issues here

  1. Windows Azure has a bug hosting Azure services in the current CTP
  2. The PDC Labs are incorrect (it only works when running inside of the Microsoft Lab PCs)

I was discussing this with Steve Marx while I was in Seattle who pointed me in the right direction.

The developer fabric in the current CTP isn’t hosting SCF services correctly. If you try and retrieve the WCF metadata, it will be returned incorrectly. So here are the steps to correctly host WCF and generate the client proxies. Note: This is my opinion based on what Steve mentioned to me, this isn’t his way.

At a high level, we need to create the WCF service, set it to basicHttpBinding, host it in the ASP.Net dev server. Get our client app to generate the proxy from the metadata. Host the WCF service in Azure, then update the client app to point to the Azure endpoint.

  1. Create a new Azure web solution
    image
  2. Right click the ASP.net application and add a new WCF service
    image
  3. Optional: Write some simple service logic.
    IHelloWorld.cs
    [ServiceContract]
    public interface IHelloWorld
    {
        [OperationContract]
        string GenerateHelloWorld();
    }
    
    HelloWorld.svc.cs
    public class HelloWorld : IHelloWorld
    {
        public string GenerateHelloWorld()
        {
            return "Hello World" + DateTime.Now;
        }
    }
  4. Open the Web.config file to change the service to basicHttpBinding. Do this by scrolling to the bottom and changing binding=”wsHttpBinding” to binding=”basicHttpBinding”
  5. Right click the ASP.Net project (AzureWCFDemo_WebRole) and set it as the startup project.
  6. Press F5 to start the ASP.Net development server. When IE starts, copy the URL into the clipboard. In this case the ASP.Net dev server generated the local port to be http://localhost:63474/HelloWorld.svc
    Leave this application running, as we will need to access a client proxy from the meta data
  7. Start a new instance of visual studio and create a windows client application
    image
  8. Right click the client project and add a new service reference. Paste in the URL to our WCF service to generate the proxy. Give it a nice name like HelloWorldService
  9. Now that our client proxy is generated, we can get the service hosted inside of Azure. Go back to our Azure project. Stop debugging to stop the asp.net application.
  10. Right click the Azure project to be the startup project, and start debugging. The dev fabric should be running and hosting our WCF service. When IE starts, notice the port number. More likely than not this will be port 81
  11. Finally, go back to our client project. Open the app.config file and change the endpoint address so that it is the port number we found in the previous step (most likely port 81)

Congratulations, you now have a scalable WCF service hosted on Azure!

By David Burela

15 thoughts on “WCF services hosted on Windows Azure

  1. Hi David… I have an imaginary HelloService that I want to make available on Azure. I want my service to be available to .Net developers all over the world at samplehello.cloudapp.net/hello.svc. I’m guessing I will tell my developer customers to add a service reference to their vs2008 project and point to my coudapp url just mentioned. I can’t seem to find a step-by-step, use-this-binding, use-this-uri article on how to make azure wcf services available to a million developers to add my service to their application. Can you point me to something like that?

  2. Well the need to do that is only because of a quirk in how they are exposing the boxes to the internet. This was going to get fixed in a later update to Azure.

  3. Is there a reference application for the deployment of public WCF services using today’s “exposed to the Internet” Azure? Or does the future promise such an application? Or do I need to understand that WCF is not meant for such public exposure and that Azure-hosted WCF services are meant to be consumed only by the same application that exposes them? (Which seems to be 100% of the samples and discussions)

  4. I’m not able to reproduce your success. Once I switch the URL to port 81, I get “The remote server returned an unexpected response: (405) Method Not Allowed.” Browsing to the svc file manually I get “HTTP Error 404.17 – Not Found. The requested content appears to be script and will not be served by the static file handler.”

  5. “HTTP Error 404.17 – Not Found. The requested content appears to be script and will not be served by the static file handler.”
    This usually means that you haven’t set IIS up correctly to serve WCF. You need to go into control panel, add/remove window features, then enable WCF

  6. I’m still wondering if and how I can make my Azure-hosted service available to the world. See my March 22 post above. Anybody?

    • Hi, Gary,
      I have the same problem which you had faced one year before. Did you fix it ?. If show can You please tell something about that.
      Thank you

Leave a comment