c# - 具有 WCF 通信的 Service Fabric 可靠服务

标签 c# wcf azure-service-fabric

我不太幸运地找到了使用 WCFCommunicationListener 的有状态可靠服务的示例。我想我的脱节是您实现运营契约(Contract)的地方。它是在主要服务类中完成的吗?您不能将 svc 文件添加到服务中,因此我假设它必须是在客户端调用 WCFCommunicationListener 时触发的其他类。

最佳答案

是的,它是在主服务类上以编程方式完成的。如果您遵循此文档,应该相当简单:https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-services-communication-wcf/

基本上就是这样:

[ServiceContract]
interface IAdderWcfContract
{
    //
    // Adds the input to the value stored in the service and returns the result.
    //
    [OperationContract]
    Task<double> AddValue(double input);

    //
    // Resets the value stored in the service to zero.
    //
    [OperationContract]
    Task ResetValue();

    //
    // Reads the currently stored value.
    //
    [OperationContract]
    Task<double> ReadValue();
}

class MyService: StatefulService, IAdderWcfContract
{
    ...
    CreateServiceReplicaListeners()
    {
        return new[] { new ServiceReplicaListener((context) =>
            new WcfCommunicationListener<IAdderWcfContract>(
                wcfServiceObject:this,
                serviceContext:context,
                //
                // The name of the endpoint configured in the ServiceManifest under the Endpoints section
                // that identifies the endpoint that the WCF ServiceHost should listen on.
                //
                endpointResourceName: "WcfServiceEndpoint",

                //
                // Populate the binding information that you want the service to use.
                //
                listenerBinding: WcfUtility.CreateTcpListenerBinding()
            )
        )};
    } 

    // implement service methods
    ...
}

关于c# - 具有 WCF 通信的 Service Fabric 可靠服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37037221/

相关文章:

c# - 自承载 WCF 服务 : How to access the object(s) implementing the service contract from the hosting application?

Azure Service Fabric 回滚

azure-service-fabric - 将元数据发布到 Service Fabric

nuget - 在 Azure Devops 上运行构建时找不到 Assets 文件 project.assets.json

c# - 使用 MVVM 时如何从 ViewModel 中访问 View 成员?

c# - 如何在 C# 中生成一个包含 3 个字母和 6 个数字的随机字母数字数组?

WCF - 如何以更面向对象的方式定义服务?

c# - DropDownlistFor MVC 4 中的 Optgroup?

c# - 让业务逻辑对象提示用户输入是不是糟糕的设计?

c# - .NET 内存使用情况(按模块)