【问题标题】:Service Fabric Reliable Service with WCF communication使用 WCF 通信的 Service Fabric 可靠服务
【发布时间】:2016-08-30 10:50:35
【问题描述】:

我没有多少运气找到使用 WCFCommunicationListener 的有状态可靠服务的示例。我想我的断开连接是您实施操作合同的地方。它是在主要服务类中完成的吗?您不能将 svc 文件添加到服务中,因此我认为它必须是在客户端调用 WCFCommunicationListener 时触发的其他类。

【问题讨论】:

    标签: c# wcf azure-service-fabric


    【解决方案1】:

    是的,它是在主服务类上以编程方式完成的。如果您遵循此文档,应该相当简单: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
        ...
    }
    

    【讨论】:

    • 是的。我发帖后才明白这一点。不过感谢您的好回答!
    猜你喜欢
    • 2018-03-13
    • 2016-02-19
    • 2020-10-24
    • 2016-12-13
    • 2017-11-04
    • 2018-12-13
    • 2016-07-26
    • 2017-12-01
    • 2016-02-17
    相关资源
    最近更新 更多