我在Azure上设置了Service Fabric群集,并且有一个运行2个服务的应用程序。现在我希望能够在我的浏览器中连接到服务,就像我在localhost上运行它一样。 该应用程序使用Owin和Swagger。以下是在localhost上运行的方式:running on localhost。当我尝试从Azure连接到它时,我收到超时错误。我在应用程序中使用端口20002和20001,并且在设置群集时打开了端口(端口19000,19080,20001和20002在我的群集中打开)。这是我在资源管理器中的服务:Service in the explorer。群集设置了证书安全性,我将证书添加到我的浏览器(我用它连接到资源管理器)。我的CreateServiceInstanceListeners代码:
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return Context.CodePackageActivationContext.GetEndpoints()
.Where(endpoint => endpoint.Protocol.Equals(EndpointProtocol.Http) || endpoint.Protocol.Equals(EndpointProtocol.Https))
.Select(endpoint => new ServiceInstanceListener(serviceContext => new OwinCommunicationListener("", new Startup(), serviceContext)));
}
和我的OpenAsync代码:
public OwinCommunicationListener(string appRoot, IOwinAppBuilder startup, StatelessServiceContext serviceInitializationParameters)
{
_startup = startup;
_appRoot = appRoot;
_parameters = serviceInitializationParameters;
}
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('/') + '/';
//TODO: Make localhost configable
_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);
}
和我的ServiceEndpoint:
<Endpoints>
<Endpoint Name="ServiceEndpoint" Port="20002" />
</Endpoints>
总结我的问题:我如何使用swagger和浏览器在我的浏览器中访问我的Service Fabric应用程序服务?
答案 0 :(得分:2)
最好的方法是在端口19081上使用反向代理。您必须在群集创建状态下启用它。
然后,您必须为反向代理设置负载均衡器规则。 Azure负载均衡器上的服务结构的基本设置没有TCP端口19081的规则,但您可以复制19000的规则。
之后例如:
然后现在您就可以到达您的服务了 http://51.140.xx.xx:19081/SampleApp/SampleService/api/values(假设您不保护反向代理端点)