错误:不包含'CreateServiceRemotingListener'的定义,也找不到包含接受第一个类型参数的扩展方法'CreateServiceRemotingListener'(是否缺少using指令或程序集引用?)
下面是我遵循的步骤,
创建了一个实现IService的接口。
`
using Microsoft.ServiceFabric.Services.Remoting;
using System.Threading.Tasks;
public interface IFileService: IService
{
Task<string> GetStringByName(string name);
}
`
状态服务中包含以下名为FileService的软件包。
`
using System. Fabric;
using Microsoft.ServiceFabric.Data;
using Microsoft.ServiceFabric.Data.Collections;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;
`
在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) };
}}
`
答案 0 :(得分:3)
ServiceRemotingExtensions类位于Microsoft.ServiceFabric.Services.Remoting.Runtime
命名空间中(不包含在内)。
要提及的重要一点是,{strong>已弃用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
派生的接口。