2
votes

I am new to Windows Azure Cloud Services. I want to host a service, built using ServiceStack, on a worker role. I have tried a few ways including the following one but no success.

Code I have tried:

public class WorkerRole : RoleEntryPoint
{
    public class AppHost : AppHostHttpListenerBase
    {
        public AppHost()
            : base("HttpListener Self-Host", typeof(HelloService).Assembly) { }

        public override void Configure(Funq.Container container)
        {
            Routes
            .Add<Hello>("/hello")
            .Add<Hello>("/hello/{Name}");
        }
    }

    public override void Run()
    {
        while (true)
        {
            Thread.Sleep(10000);
            Trace.TraceInformation("Working", "Information");
        }
    }

    public override bool OnStart()
    {
        // Set the maximum number of concurrent connections 
        ServicePointManager.DefaultConnectionLimit = 12;

        // For information on handling configuration changes
        // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.       

        try
        {
            var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"];
            string baseUri = string.Format("{0}://{1}/", endpoint.Protocol, endpoint.IPEndpoint);

            var appHost = new AppHost();
            appHost.Init();
            appHost.Start(baseUri);
        }
        catch (Exception e)
        {
            Trace.TraceError("Could not start service host. {0}", e.Message);
        }

        return base.OnStart();
    }
}

Service is deployed successfully but I am unable to access the service.

1
So what is the exception?Scott
You might want to watch this video. While it's not ServiceStack the principals are the same. Ensure that you have configured your endpoint access correctly.Scott
Did you check the operational logs? are there any errors?vainolo
Actually the app host is being started and no exception is being thrown while starting app host. I printed out the IP Endpoint of worker role in trace and used that to send request browser cant find that. Although if i run this project on local machine it works fine. I followed following links for ServiceStack self-hosting and deploying API on worker role: github.com/ServiceStack/ServiceStack/wiki/Self-hosting asp.net/web-api/overview/hosting-aspnet-web-api/…Haider
Haider - did you ever get this working? I'm looking at doing something similar.Erick T

1 Answers

2
votes

Are you running it with elevated priviledges? In order to open an HTTP port you need to run as an administrator. You can do this by adding <Runtime executionContext="elevated" /> to your worker role in the service definition.

Alternatively you could make a startup script (which of course has to run in elevated mode) to run a netsh command allowing you to open the ports without elevated priviledges.