【发布时间】:2018-10-16 05:56:39
【问题描述】:
我创建了一个 .NET Core 无状态 Service Fabric 应用程序 (v 3.0.467)。我需要为此服务同时使用 KestrelCommunicationListener 和 ServiceProxy 远程调用。
当我将应用程序部署到本地集群时,它会抛出异常:
我在 servicemanifest.xml 文件中进行了如下配置
<Resources>
<Endpoints>
<!-- This endpoint is used by the communication listener to obtain the port on which to
listen. Please note that if your service is partitioned, this port is shared with
replicas of different partitions that are placed in your code. -->
<Endpoint Name="ServiceEndpointV2" />
<Endpoint Protocol="http" Name="httpServiceEndpoint" Type="Input" Port="9098" />
</Endpoints>
</Resources>
和代码示例:
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[]
{
new ServiceInstanceListener((context) =>
{
// return new FabricTransportServiceRemotingListener(context, this);
return new FabricTransportServiceRemotingListener(context, this,new Microsoft.ServiceFabric.Services.Remoting.FabricTransport.Runtime.FabricTransportRemotingListenerSettings(){EndpointResourceName = "ServiceEndpointV2" });
}),
new ServiceInstanceListener(serviceContext =>
new KestrelCommunicationListener(serviceContext, "httpServiceEndpoint", (url, listener) =>
{
ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");
return new WebHostBuilder()
.UseKestrel()
.ConfigureServices(
services => services
.AddSingleton<StatelessServiceContext>(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseUrls(url)
.Build();
}))
};
}
这个配置有错误吗?
更新:
以下代码是客户端调用的服务示例方法:
public Task<string> OnRouteMessageaAsync(string tenant)
{
return Task.FromResult(tenant);
}
客户端代码:
private async Task<string> RemoteServiceCall()
{
try
{
var client = ServiceProxy.Create<ICommunication>(new Uri("fabric:/AuthenticationServiceApp/AuthenticationServiceApi"), listenerName: "RemotingListener");
var response = client.OnRouteMessageaAsync("tenant");
return response.Result;
}
catch (Exception ex)
{
}
return null;
}
示例代码位于以下 GitHub 链接中: serviceappcode
【问题讨论】:
标签: azure azure-service-fabric service-fabric-stateless