Search code examples
service-fabric-statelessazure-service-fabricservice-fabric-on-premises

Asp.Net Core StateLess Serivce Calling StateLess Serice in Azue Service Fabric


I am trying to call a stateless service from Asp.Net Core Stateless API. I am not able to reach the methods in Stateless Service.

This is the Controller action method which will call the stateless service method.

 // GET api/values
    [HttpGet]
    public async Task<string> GetAsync()
    {
        var repository = ServiceProxy.Create<IRepository>(
            new Uri("fabric:/Application1/Stateless1"));
        return await repository.GetSomething();
        //return new string[] { "value1", "value2" };
    }

This is the method in Stateless service.

    internal sealed class Stateless1 : StatelessService, IRepository
    {
    public Stateless1(StatelessServiceContext context)
        : base(context)
    { }

    public async Task<string> GetSomething()
    {
        return await Task.FromResult("HELLO FROM SERVICE!");
    } 
    }

And the listener code is

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
    {
        return this.CreateServiceInstanceListeners();
    }

I am able to hit the controller Get method but it is struck at repository.GetSomething() method and not able to reach that method. I don't know what I am missing here.

Any pointers will be very helpful. Thanks in advance

Update:

Manifest file:

enter image description here


Solution

  • You need to change your CreateServiceInstanceListeners...

    protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
    {
       return this.CreateServiceRemotingInstanceListeners();  
    }
    

    It needs the remoting listener as using the ServiceProxy is a remoting call.