我在 Service Fabric 6 上有一个 Asp.net Core 2.0 无状态服务和一个 Asp.net Core 2.0 有状态服务,分区数为 10。
我跟着这个教程
https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-add-a-web-frontend
我遵循了所有步骤,除了我在 Visual Studio 中使用了 CreateServiceReplicaListeners 使用 KestrelCommunicationListener 的模板
protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
{
return new ServiceReplicaListener[]
{
new ServiceReplicaListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, (url, listener) =>
{
return new WebHostBuilder()
.UseKestrel()
.ConfigureServices(
services => services
.AddSingleton<StatefulServiceContext>(serviceContext)
.AddSingleton<IReliableStateManager>(this.StateManager))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
.UseUrls(url)
.Build();
}))
};
}
当我使用以下代码在 Asp.net Core 2.0 Stateless 服务中调用我的服务时:
var service = ServiceProxy.Create<IStorageService>(new Uri("fabric:/MyCluster/Storage"), new ServicePartitionKey(Fnv1aHashCode.Get64bitHashCode(User.Id)));
await service.MyMethod();
调用“MyMethod”时引发异常
客户端正在尝试连接到无效地址http://localhost:58352/etc ..
异常中存在的 url 存在于 Service Fabric Explorer 中,并且 Port 和 PartitionKey 是正确的。ServiceManifest 中没有设置端点,因为有状态服务基本上只是添加了 IService 接口和 MyMethod 方法的模板,如上面的教程。
我在这里缺少什么?Asp.net Core 2.0 的文档不是最新的。
我试图不使用分区,设置 ServicePartitionKey(0)
但结果相同。
我不知道该怎么做。