【问题标题】:There is no implicit reference conversion from StatelessService to 'Microsoft.ServiceFabric.Services.Remoting.IService'没有从 StatelessService 到“Microsoft.ServiceFabric.Services.Remoting.IService”的隐式引用转换
【发布时间】:2017-11-25 15:17:00
【问题描述】:

我正在编写一个新的 azure 服务应用程序,它可以使用服务远程处理进行通信。 我引用了this article。我面临错误:

类型“PushMsgStatelessService.PushMsgStatelessService”不能用作泛型类型或方法“ServiceRemotingExtensions.CreateServiceRemotingListener(TStatelessService, StatelessServiceContext)”中的类型参数“TStatelessService”。没有从“PushMsgStatelessService.PushMsgStatelessService”到“Microsoft.ServiceFabric.Services.Remoting.IService”的隐式引用转换。 PushMsgStatelessService C:\Nirvana\DataPerPerson\Narendra\PushMessageService\PushMsgStatelessService\PushMsgStatelessService.cs 30 活动

我的代码:

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

我被困在这里了。

【问题讨论】:

    标签: azure communication microservices azure-service-fabric stateless


    【解决方案1】:

    您应该在您的界面中添加对IService 界面的引用。所以把你的interface IPushMessageService改成interface IPushMessageService : IService

    侧节点 1:您可能应该公开您的界面。

    侧节点 2:最好将您的界面放在一个单独的项目中,以防止在使用远程处理时出现任何循环依赖。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 1970-01-01
      相关资源
      最近更新 更多