2016-05-04 64 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

呀。我发布后我发现了这一点。谢谢你的好回答! –