I am writing a new azure service application which can communicate using service remoting. I referenced this article. I am facing error:
The type 'PushMsgStatelessService.PushMsgStatelessService' cannot be used as type parameter 'TStatelessService' in the generic type or method 'ServiceRemotingExtensions.CreateServiceRemotingListener(TStatelessService, StatelessServiceContext)'. There is no implicit reference conversion from 'PushMsgStatelessService.PushMsgStatelessService' to 'Microsoft.ServiceFabric.Services.Remoting.IService'. PushMsgStatelessService C:\Nirvana\DataPerPerson\Narendra\PushMessageService\PushMsgStatelessService\PushMsgStatelessService.cs 30 Active
My code:
using System.Collections.Generic;
using System.Fabric;
using System.Threading.Tasks;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;
using Microsoft.ServiceFabric.Services.Remoting.Runtime;
namespace PushMsgStatelessService
{
interface IPushMessageService
{
Task<string> GetMessageAsync();
}
/// <summary>
/// An instance of this class is created for each service instance by the Service Fabric runtime.
/// </summary>
internal sealed class PushMsgStatelessService : StatelessService, IPushMessageService
{
public PushMsgStatelessService(StatelessServiceContext context)
: base(context)
{ }
public Task<string> GetMessageAsync()
{
return Task.FromResult("Hello!");
}
/// <summary>
/// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests.
/// </summary>
/// <returns>A collection of listeners.</returns>
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[] { new ServiceInstanceListener(context => this.CreateServiceRemotingListener(context)) };
}
}
}
I am stuck here.
You should add a reference to the IService
interface in your interface. So change your interface IPushMessageService
to interface IPushMessageService : IService
.
Side node 1: You should probably make your interface public.
Side node 2: It is better to put your interface in a separate project to prevent any circular dependencies when working with remoting.