簡體   English   中英

WCF通信的Service Fabric可靠服務

[英]Service Fabric Reliable Service with WCF communication

使用WCFCommunicationListener來查找有狀態可靠服務的示例並不太幸運。 我想我的脫節是您執行運營合同的地方。 是在主服務類中完成的嗎? 您無法將svc文件添加到服務,因此我認為它必須是客戶端調用WCFCommunicationListener時觸發的其他某個類。

是的,它是在主要服務類上以編程方式完成的。 如果您遵循此文檔,則應該做起來非常簡單: https : //azure.microsoft.com/zh-cn/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
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM