2016-05-04 88 views
2

我沒有多少運氣找到一個使用WCFCommunicationListener的有狀態可靠服務的例子。我想我的斷開是你實施運營合同的地方。它在主要服務類中完成了嗎?你不能添加一個svc文件到服務,所以我認爲它必須是一些其他的類,當客戶端調用WCFCommunicationListener時被觸發。服務結構WCF通信的可靠服務

回答

5

是的,它是在主服務類上以編程方式完成的。如果按照這個文檔應該是相當簡單的事情: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 
    ... 
} 
+0

呀。我發佈後我發現了這一點。謝謝你的好回答! –