0

我正在编写一个新的可以使用服务远程进行通信的azure服务应用程序。 我引用了this article。我面对错误:没有从StatelessService到'Microsoft.ServiceFabric.Services.Remoting.IService'的隐式引用转换

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

我的代码:

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)) }; 
     } 
    } 
} 

我在这里停留。

回答

0

您应该在界面中添加对IService界面的引用。因此请将您的interface IPushMessageService更改为interface IPushMessageService : IService

边节点1:您应该公开您的接口。

边节点2:最好将您的接口放在单独的项目中,以防止在使用远程处理时出现任何循环依赖关系。

+0

谢谢,这解决了我的问题。 –