WCF Azure Worker Role on HTTP port 80

This sample creates a simple WCF worker that is able to accept connections through port 80 without IIS using a startup script running in elevated permissions.

 
 
 
 
 
3.8 Star
(6)
Add to favorites
4/27/2011
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Sample
    1 Posts | Last post February 24, 2012
    • Please provide the sample project.I am new to windows applications.I am not getting the  Copy to Output  concept.
      If you provide the sample appplication it would be helpfull...
  • Load Balancing on Worker role
    1 Posts | Last post June 17, 2011
    • How will this thing behave when running multiple instances of the worker role?
      Thanks!
  • Not really a question...
    1 Posts | Last post April 21, 2011
    • Massive props to you my friend! I've been poking around at Worker Roles, trying to successfully deploy one to the cloud and your console application finally did the trick!
      
      The amazing thing is the fact that I wasn't able to find anyone else explaining this... so thanks! Loads! :D
  • Also problem with getting this to work...
    2 Posts | Last post March 08, 2011
    • Hi Brandon,
      
      hm, my role keeps recycling when I deploy it to the Cloud.
      What is you MS email alias? Then I can send you my sample SLN if this is OK.
      
      I am v-cweyer.
      Thanks.
    • Emailed!
  • Fails when uploading to azure
    5 Posts | Last post March 05, 2011
    • I was planning on using this method to host an external facing WCF service on Azure, but I can't get your solution to work. 
      
      When I try publishing it to Azure it fails on initializing. It does not give any error message. 
      Do you know why this happens?
      
      Why is the netsh call even necessary? Do Azure worker roles not support external http endpoints without it?
      Is this the only way to do that?
    • My guess is that the startup script has not executed properly. I would make sure in Visual Studio AzurePortDetector.exe is found and Copy to Output is set to "Copy Always" (this should be the case right out of the box).
      
      Netsh is required as accessing HTTP ports requires admin privileges. There is another way to open an HTTP and that is to run the worker role with elevated permissions. This is, however, not recommended.
    • The file is found and is set to copy always. 
      I tried to run a worker role with elevated permissions to open the service, and logging the exceptions. 
      What I got was:
      HTTP could not register URL http://*:20000/myservice/. Your process does not have access rights to this namespace. 
      If I use HostNameComparisonMode.Exact I can get it to run without that exception, but then I can't connect to it. 
      Do you know why this happens, and a way to get it to work?
    • The above post was from me, wrong account. 
    • Try changing http:// :{0}/Service to http:// :{0}/myservice in AzurePortDetector/Program.cs.
  • need info how to host this sample in cloud
    2 Posts | Last post February 18, 2011
    • This example is very basic which can give you more understanding of concept. 
      and i am looking for how we can host WCF service in worker role and your example does this. 
      
      Can i this say what the code is achieving is hosting a WCF service using worker role in IIS ? 
      
      And can i add this service to my client application using "add service reference" in my Visual studio ? 
      i tried but didn't worked. i didn't understand the client application that you have written. especially this line 
      
      Process.Start("netsh", string.Format("http add urlacl url=http://+:{0}/Service user=everyone listen=yes delegate=yes",
      
      i deployed this cloud and not able to go further using the service in my client application . 
      Will be thank full if you share how can i do this . 
    • Worker roles work independently of IIS. If you would like to use the service using Add Service Reference or svcutil, you need to expose the metadata (MEX) endpoint (http://bloggingabout.net/blogs/dennis/archive/2006/11/09/WCF-Part-4-_3A00_-Make-your-service-visible-through-metadata.aspx). 
      
      An alternative method (since it seems you are designing both the service and the consuming client), would be to use a ChannelFactory. For example, in the case of this example, the client can use something like:
      
      ChannelFactory<IService> factory = new ChannelFactory<IService>(new BasicHttpBinding(), "http://brandonTest.cloudapp.net:80/Service");
      factory.Open();
      IService service = factory.CreateChannel();
      ((IChannel)service).Open();
      service.Call("foo"); //As if you used Add Service Reference/svcutil
      
      The line Process.Start("netsh",...); just calls the command line utility "netsh" to enable users to open a port allocated by Azure. This could technically sit in a .cmd/.bat file but we need to get the specific port from Azure. We get that port using RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["HttpInput"].IPEndpoint.Port.ToString().
      
      Hope that helps!
      
      -Brandon