0

错误:不包含“CreateServiceRemotingListener”的定义,并且找不到接受第一个类型参数的扩展方法“CreateServiceRemotingListener”(您是否缺少 using 指令或程序集引用?)

以下是我遵循的步骤,

  1. 创建了一个实现 IService 的接口。

    `

        using Microsoft.ServiceFabric.Services.Remoting;
        using System.Threading.Tasks;
        public interface IFileService: IService
        {
            Task<string> GetStringByName(string name);
        }
    

    `

  2. 在名为 FileService 的有状态服务中包含以下包。

    `

     using System. Fabric;
        using Microsoft.ServiceFabric.Data;
        using Microsoft.ServiceFabric.Data.Collections;
        using Microsoft.ServiceFabric.Services.Communication.Runtime;
        using Microsoft.ServiceFabric.Services.Runtime;
    

    `

  3. 在 FileService 中实现了 IFileService 接口。

    `

     internal sealed class FileService : StatefulService, IFileService
        {
            public FileService(StatefulServiceContext context)
                : base(context)
            { }
            public FileService(StatefulServiceContext context, IReliableStateManagerReplica stateManagerReplica) : base(context, stateManagerReplica)
            {
            }
    
            public Task<string> GetStringByName(string name)
            {
                return Task.FromResult<string>(name);
            }
    
    
            /// <summary>
            /// Optional override to create listeners (e.g., HTTP, Service Remoting, WCF, etc.) for this service replica to handle client or user requests.
            /// </summary>
            /// <remarks>
            /// For more information on service communication, see https://aka.ms/servicefabricservicecommunication
            /// </remarks>
            /// <returns>A collection of listeners.</returns>
            protected override IEnumerable<ServiceReplicaListener> 
    
        CreateServiceReplicaListeners()
                {
                    return new[] { new ServiceReplicaListener(this.CreateServiceRemotingListener) };
                }}
    

    `

4

1 回答 1

3

ServiceRemotingExtensions类位于命名空间中Microsoft.ServiceFabric.Services.Remoting.Runtime(不包括在内)。

要提到的重要一点CreateServiceRemotingListener已弃用。推荐使用的方法是CreateServiceRemotingReplicaListeners

希望这可以帮助。


更新 2019/01/28

这是示例代码:

using System.Collections.Generic;
using System.Fabric;

using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Remoting;
using Microsoft.ServiceFabric.Services.Remoting.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;

namespace JustService
{
    public interface IRemotingService : IService
    {
        // Remoting methods
    }
    internal sealed class JustService : StatefulService, IRemotingService
    {
        public JustService(
            StatefulServiceContext context)
            : base(context)
        {
        }
        protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
        {
            return this.CreateServiceRemotingReplicaListeners();
        }
    }
}

请注意,为了使用CreateServiceRemotingReplicaListeners扩展方法,服务应该实现一个从IService.

于 2018-10-23T15:12:41.730 回答