具有 WCF 通信的 Service Fabric 可靠服务
Service Fabric Reliable Service with WCF communication
我不太幸运地找到了使用 WCFCommunicationListener 的有状态可靠服务的示例。我想我的脱节是您实施运营合同的地方。是在主服务class中完成的吗?您不能将 svc 文件添加到服务,所以我假设它必须是其他一些 class,当客户端调用 WCFCommunicationListener 时触发。
是的,它是在主要服务 class 上以编程方式完成的。如果您遵循此文档,应该相当简单: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
...
}
我不太幸运地找到了使用 WCFCommunicationListener 的有状态可靠服务的示例。我想我的脱节是您实施运营合同的地方。是在主服务class中完成的吗?您不能将 svc 文件添加到服务,所以我假设它必须是其他一些 class,当客户端调用 WCFCommunicationListener 时触发。
是的,它是在主要服务 class 上以编程方式完成的。如果您遵循此文档,应该相当简单: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
...
}