I’ve gotten quite a few questions asking how to get WCF services working correctly under Windows Azure. There are 2 main issues here
- Windows Azure has a bug hosting Azure services in the current CTP
- 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.
- Create a new Azure web solution
- Right click the ASP.net application and add a new WCF service
- 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; } }
- 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”
- Right click the ASP.Net project (AzureWCFDemo_WebRole) and set it as the startup project.
- 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 - Start a new instance of visual studio and create a windows client application
- 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
- 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.
- 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
- 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!
Can you be a bit more specific and provide an example of the endpoint.
e.g.
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?
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.
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)
Hi David. Thanks for publishing this article. This was extremely helpful in helping to understand how to move services from windows hosting into Azure hosting. you may also want your readers to be aware of not being able to generate proxies against Azure hosted WCF services and the work-arounds described here: http://code.msdn.microsoft.com/wcfazure/Wiki/View.aspx?title=KnownIssues
After reading the article, I feel that I need more info. Can you share some more resources ?
There is an article that provides a good workaround on this problem.
http://geekswithblogs.net/bloesgen/archive/2008/12/21/128098.aspx
Thanks
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.”
“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
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
No, I never did figure this out. 😦 I concluded that Azure was not designed nor fit to host services publicly on the Internet in the manner I described above on March 22, 2009. Good luck.
I’ll be posting a new article this week which may help.
[…] 9/12/2008 how to host WCF on Azure https://davidburela.wordpress.com/2008/12/09/wcf-services-hosted-on-windows-azure/ […]
Gary: Lets hope 🙂
David: Thanks, I will be waiting..