Service Fabric,将 V2 远程处理到有状态服务不起作用

Service Fabric, Remoting V2 to Stateful Service not working

我无法正常工作,我用谷歌搜索了一下,可能找到了关于如何执行此操作的所有页面,所有两个页面!

基本上,我只是想让 SF Remoting V2 从无状态 .NET Core 2 MVC 应用程序工作到有状态服务。

这是我所做的:

控制器中的客户端代码:(尽可能简化):

public class ValuesController : Controller
{

    [HttpGet]
    public async Task<IEnumerable<string>> Get()
    {

         // Provide certificate details.
        var serviceProxyFactory = new ServiceProxyFactory((c) => new FabricTransportServiceRemotingClientFactory());

        var proxy = serviceProxyFactory.CreateServiceProxy<ICallMe>(new Uri("fabric:/SFExperiment/Stateful1"));

        var value3 = await proxy.GetGreeeting("Bob");

        return new[] { "value1", "value2", value3 };
    }

服务代码接口:

using System.Threading.Tasks;
using Microsoft.ServiceFabric.Services.Remoting;
using Microsoft.ServiceFabric.Services.Remoting.FabricTransport;


[assembly: FabricTransportServiceRemotingProvider(RemotingListener = 
RemotingListener.V2Listener, RemotingClient = RemotingClient.V2Client)]

namespace Stateful1.Abstractions
{

 public interface ICallMe : IService
 {
     Task<string> GetGreeeting(string name);
 }
}

服务代码:

    Public sealed class Stateful1 : StatefulService, ICallMe
{
    public Stateful1(StatefulServiceContext context)
        : base(context)
    { }

    protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
    {
        return this.CreateServiceRemotingReplicaListeners();
    }

    public Task<string> GetGreeeting(string name)
    {
        return Task.FromResult(@"Congratulations, you have remoting working. :-) ");
    }

我已在下面添加到 ServiceManifest.xml

  <Resources>
<Endpoints>
  <!-- To enable Service remonting for remoting services V2-->
  <Endpoint Name="ServiceEndpointV2" />

  <Endpoint Name="ReplicatorEndpoint" />
</Endpoints>
</Resources>

它不起作用..我得到以下异常:

选择器 {1}

的分区 key/ID“{0}”无效

我做错了什么?

在创建服务代理的调用中,您必须指定分区键,因为您正在连接到有状态服务。

long partitionKey = 0L;  //TODO: Determine partition key
var proxy = serviceProxyFactory.CreateServiceProxy<ICallMe>(new Uri("fabric:/SFExperiment/Stateful1"), new ServicePartitionKey(partitionKey), TargetReplicaSelector.PrimaryReplica);

此外,请确保重用您的服务代理工厂,而不是创建一个新工厂。 例如看一下 this 代码。