过去几周我一直在从云服务迁移到 Service Fabric,并且在两个服务之间使用远程处理时遇到了一些障碍。
我一直在使用服务远程处理的官方文档和示例代码,特别是我试图让此处概述的示例正常工作:
https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-remoting https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-remoting
我有2个服务。一个被命名为“远程服务”另一个被命名为“来电服务”。两者都源自默认的无状态服务项目。
在这两个“远程服务” and “来电服务”项目我添加了以下接口来描述它们之间的服务契约:
public interface IMyService : IService
{
Task<string> HelloNameAsync(string name);
}
In the “远程服务”我已经在远程服务类中创建了关联的方法
public Task<string> HelloNameAsync(string name)
{
return Task.FromResult("Hello " + name + "!");
}
我也覆盖创建服务实例监听器与以下
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[] { new ServiceInstanceListener(context => this.CreateServiceRemotingListener(context)) };
}
In my “来电服务”当我尝试连接时,使用以下命令调用“RemoteService”:
IMyService helloNameClient = ServiceProxy.Create<IMyService>(new Uri("fabric:/Application/RemoteService"));
string message = await helloNameClient.HelloNameAsync("Luke");
我得到这个异常
InnerException = {"Interface id '1994370306' is not implemented by object 'RemoteService.RemoteService'"}
我用细齿梳子仔细检查了这个样本,并确信一切都已就位。我读过有关设置端点并将服务注册到服务目录中的内容,但据我了解,这些是针对外部服务的,并且远程处理文档没有提到需要这样做。
UPDATE:
以下是 RemoteService 类的声明方式:
internal sealed class RemoteService : StatelessService, IMyService
UPDATE 2
以下是这两种服务的 Settings.xml 的样子。这些是项目开箱即用的默认设置。我没有添加或删除任何东西。我还想指出,我正在本地服务结构上运行所有这些。
<?xml version="1.0" encoding="utf-8" ?>
<Settings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<!-- Add your custom configuration sections and parameters here -->
<!--
<Section Name="MyConfigSection">
<Parameter Name="MyParameter" Value="Value1" />
</Section>
-->
</Settings>