Calling services from another application in the cluster

Can I call services or members from one application to another in a Fab Fabric cluster? When I tried (using ActorProxy.Create with the correct Uri), I got "No MethodDispatcher for the interface"

+1
azure-service-fabric
source share
1 answer

Yes it is possible . As long as you have the Uri right to the Service (or ActorService), and you have access to the assembly with an interface that defines your service or actor, this should not differ much from calling the Service / Actor from one application. You have security enabled for your service , then you also need to install certificates for exchange.

If I have a simple service that is defined as:

public interface ICalloutService : IService { Task<string> SayHelloAsync(); } internal sealed class CalloutService : StatelessService, ICalloutService { public CalloutService(StatelessServiceContext context) : base(context) { } protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() { yield return new ServiceInstanceListener(this.CreateServiceRemotingListener); } public Task<string> SayHelloAsync() { return Task.FromResult("hello"); } } 

and simple actor:

 public interface ICalloutActor : IActor { Task<string> SayHelloAsync(); } [StatePersistence(StatePersistence.None)] internal class CalloutActor : Actor, ICalloutActor { public CalloutActor(ActorService actorService, ActorId actorId) : base(actorService, actorId) {} public Task<string> SayHelloAsync() { return Task.FromResult("hello"); } } 

works in the following application:

Fabric Explorer

Then you can call it from another application in the same cluster:

  // Call the service var calloutServiceUri = new Uri(@"fabric:/ServiceFabric.SO.Answer._41655575/CalloutService"); var calloutService = ServiceProxy.Create<ICalloutService>(calloutServiceUri); var serviceHello = await calloutService.SayHelloAsync(); // Call the actor var calloutActorServiceUri = new Uri(@"fabric:/ServiceFabric.SO.Answer._41655575/CalloutActorService"); var calloutActor = ActorProxy.Create<ICalloutActor>(new ActorId(DateTime.Now.Millisecond), calloutActorServiceUri); var actorHello = await calloutActor.SayHelloAsync(); 

You can find the correct Uri in Fabric Explorer if you click on a service and look at the name. The default service Uri is: fabric:/{applicationName}/{serviceName} .

The only tricky part is how to 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 "The id id {xxxxxxxx} 'is not implemented by the' {service} '' object, and if you do this for the Actor, you will receive a KeyNotfoundException message" No Dispatcher method found for the id interface - {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