2014-01-20 97 views
2

我是Windows Azure雲服務新手。我想在一個worker角色上託管一個使用ServiceStack構建的服務。我嘗試了幾種方法,包括下面的方法但沒有成功。使用Windows Azure工作者角色託管ServiceStack

碼我曾嘗試:

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(); 
    } 
} 

服務部署成功,但我無法訪問該服務。

+0

那麼什麼是例外? – Scott

+0

您可能想要觀看[此視頻](http://channel9.msdn.com/Series/Windows-Azure-Cloud-Services-Tutorials/Introduction-to-Windows-Azure-Worker-Roles-Part-1)。雖然不是ServiceStack,但校長是一樣的。確保您已正確配置您的端點訪問。 – Scott

+0

你檢查了操作日誌嗎?有沒有錯誤? – vainolo

回答

2

你是否正在運行它與特權提升?爲了打開HTTP端口,您需要以管理員身份運行。您可以通過將<Runtime executionContext="elevated" />添加到服務定義中的輔助角色來完成此操作。

或者,您可以創建啓動腳本(當然必須以提升模式運行)至run a netsh command,以允許您在沒有提升權限的情況下打開端口。

+0

它沒有工作。請在問題文章下看到我的意見。 – Haider

相關問題