我正在與Owin一起開發Service Fabric項目,並且遇到了將其部署到雲中的問題。我已經搜索了同樣的問題,但我只找到了一個答案,告訴羣集中的錯誤告訴代碼出錯了。我已經按照微軟Owin教程介紹瞭如何編寫失敗的方法,但沒有運氣。 我可以直接從Visual Studio在Localhost上運行項目,但是當我將它部署到Azure中的Service Fabric集羣時,問題就會出現。我有5個節點的羣集正在運行,當我部署到它時,它會在2分鐘後發出警告,5分鐘後會發生錯誤。該應用程序的狀態是「inbuild」。 Image of warning和Image of error。與Owin部署Service Fabric項目到Azure服務Fabric羣集的問題
我有兩個服務,並從我的羣集的錯誤給出了這兩種方法的錯誤(同樣的方法在每個服務(OpenAsync)):
public Task<string> OpenAsync(CancellationToken cancellationToken)
{
var serviceEndpoint =
_parameters
.CodePackageActivationContext
.GetEndpoint("ServiceEndpoint");
var port = serviceEndpoint.Port;
var root =
String.IsNullOrWhiteSpace(_appRoot)
? String.Empty
: _appRoot.TrimEnd('/') + '/';
_listeningAddress = String.Format(
CultureInfo.InvariantCulture,
"http://+:{0}/{1}",
port,
root
);
_serverHandle = WebApp.Start(
_listeningAddress,
appBuilder => _startup.Configuration(appBuilder)
);
var publishAddress = _listeningAddress.Replace(
"+",
FabricRuntime.GetNodeContext().IPAddressOrFQDN
);
ServiceEventSource.Current.Message("Listening on {0}", publishAddress);
return Task.FromResult(publishAddress);
}
從集羣中的錯誤告訴錯誤在本節:
_serverHandle = WebApp.Start(
_listeningAddress,
appBuilder => _startup.Configuration(appBuilder)
);
其他方法(從其他服務):
public Task<string> OpenAsync(CancellationToken cancellationToken)
{
var serviceEndpoint =
_parameters
.CodePackageActivationContext
.GetEndpoint("ServiceEndpoint");
var port = serviceEndpoint.Port;
var root =
String.IsNullOrWhiteSpace(_appRoot)
? String.Empty
: _appRoot.TrimEnd('/') + '/';
_listeningAddress = String.Format(
CultureInfo.InvariantCulture,
"http://+:{0}/{1}",
port,
root
);
try
{
_serverHandle = WebApp.Start(
_listeningAddress,
appBuilder => _startup.Configuration(appBuilder)
);
}
catch (Exception e)
{
Console.WriteLine(e);
throw e;
}
var publishAddress = _listeningAddress.Replace(
"+",
FabricRuntime.GetNodeContext().IPAddressOrFQDN
);
ServiceEventSource.Current.Message("Listening on {0}", publishAddress);
return Task.FromResult(publishAddress);
}
從集羣中的錯誤告訴錯誤是在本節:
try
{
_serverHandle = WebApp.Start(
_listeningAddress,
appBuilder => _startup.Configuration(appBuilder)
);
}
catch (Exception e)
{
Console.WriteLine(e);
throw e;
}
我的啓動類:
public void Configuration(IAppBuilder appBuilder)
{
var corsAttr = new EnableCorsAttribute(origins: "*", headers: "*", methods: "*");
var config = new HttpConfiguration();
config.WithWindsorSetup();
config.WithJsonSetup();
config.MapHttpAttributeRoutes(); //Enable Attribute-routing
config.WithSwaggerSetup();
config.EnsureInitialized();
config.EnableCors(corsAttr);
appBuilder.UseWebApi(config);
}
,並在那裏創建一個新的OwenCommunicationListener:
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[] {
new ServiceInstanceListener(initParams => new OwinCommunicationListener("", new Startup.Startup(), initParams))
};
}
我非常希望能夠無任何錯誤地將其部署到Azure服務Fabric羣集。祝你有美好的一天,並感謝您的幫助。
感謝您的回答。我已經寫了我自己的自定義Startup類,並在創建OwinCommunicationListener的新實例的地方使用它。我在原始文章中添加了代碼 – ptr