Customer Service

In the past few weeks, I have moved from cloud services to service fabric and started working on several stumbling blocks using Remoting between the two services.

I use the official documentation and sample code for the Remoting service, and in particular, I am trying to get the sample described here to work:

https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-remoting

I have 2 services. One of them is called "RemoteService" , and the other is called "CallerService" . Both are derived from the default Stateless Service project.

In the "RemoteService" and "CallerService" projects, I added the following interface to describe the service contract between them:

public interface IMyService : IService { Task<string> HelloNameAsync(string name); } 

In "RemoteService", I created an asociated method in the RemoteService class

 public Task<string> HelloNameAsync(string name) { return Task.FromResult("Hello " + name + "!"); } 

I also override CreateServiceInstanceListeners with the following

 protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() { return new[] { new ServiceInstanceListener(context => this.CreateServiceRemotingListener(context)) }; } 

In my "CallerService" , when I try to connect, make a call to "RemoteService" with the following:

 IMyService helloNameClient = ServiceProxy.Create<IMyService>(new Uri("fabric:/Application/RemoteService")); string message = await helloNameClient.HelloNameAsync("Luke"); 

I get this exception

 InnerException = {"Interface id '1994370306' is not implemented by object 'RemoteService.RemoteService'"} 

I passed this sample with a thin comb and I am sure that I have everything in place, as it should be. I read about configuring endpoints and registering your services in the service directory, but from what I understand, this is for external services, and this is not mentioned in the Remoting documentation.

UPDATE:

This is how the RemoteService class is declared:

 internal sealed class RemoteService : StatelessService, IMyService 

UPDATE 2

This is what Settings.xml looks like for both services. These are the default settings that go out of the box with the project. I did not add or remove anything. I also want to note that I am doing all this on my local service.

 <?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> 
+3
c # azure azure-service-fabric
source share
1 answer

The aggregation in which the service interface is declared needs to be shared with the client; you cannot recreate an identical interface on the client side. When the Service Fabric establishes a connection, it creates an interface map and uses the methods from the actual assembly used by the service.

Based on your description, it looks like you are declaring an identical interface in both the service and the client project? If so, then this is a fix.

From SO: calling services from another application in the cluster : The only tricky part is how do you get the interface from the external service to your calling service? You can simply reference the built-in .exe for the service you want to call, or you can pack the assembly containing the interface in the form of a NuGet package and put a personal channel.

If you do not, and instead you just pass the code between your Visual Studio solutions, the Fabric service will think that these are two different interfaces, even if they have the same signature. If you do this for the Service, you will receive a NotImplementedException message in which the "Interface id" {xxxxxxxx} 'is not implemented by the object' {service} '', and if you do this for the Actor, you will receive a KeyNotfoundException that says: "No MethodDispatcher not found for interface id '- {xxxxxxxxxx}' ".

So, to fix your problem, make sure that you reference the same assembly that is in the application that you want to invoke in the external application that invokes.

+5
source share

All Articles