我无法解决这个问题,我已经用Google搜索过,并且可能会找到关于如何执行此操作的每一页,所有这两个页面都可以!
基本上我只是试图从无状态.NET Core 2 MVC应用程序中获取SF Remoting V2'为国家服务。
这就是我所做的:
控制器中的客户端代码:(尽可能简化):
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>
它不起作用..我得到以下例外:
无效的分区键/ ID&#39; {0}&#39;选择器{1}
我做错了什么?
答案 0 :(得分:3)
在创建服务代理的调用中,您必须指定分区键,因为您要连接到有状态服务。
long partitionKey = 0L; //TODO: Determine partition key
var proxy = serviceProxyFactory.CreateServiceProxy<ICallMe>(new Uri("fabric:/SFExperiment/Stateful1"), new ServicePartitionKey(partitionKey), TargetReplicaSelector.PrimaryReplica);
此外,请确保重复使用服务代理工厂,而不是创建新工厂。 例如,请查看this代码。