无法找到使用WcfCommunicationListener的无状态服务

时间:2017-01-16 21:15:51

标签: azure-service-fabric service-fabric-stateful

我正在尝试使用IServiceProxyFactory CreateServiceProxy方法找到我的无状态服务。它似乎找到了服务实例,但是当我调用一个方法时,它会收到一个错误"Client is trying to connect to invalid address net.tcp://localhost..."。无状态服务使用WcfCommunicationListener。

1 个答案:

答案 0 :(得分:1)

IServiceProxyFactory的默认实现是ServiceProxyFactory,它会创建FabricTransportServiceRemotingClientFactory的实例,而后者又会为您提供FabricTransportServiceRemotingClient。这个使用TCP上的Fabric传输进行通信(顾名思义)。 Fabric传输期望服务在fabric:/applicationname/servicename等地址上具有结构传输侦听器FabricTransportServiceRemotingListener

如果要使用WcfCommunicationListener连接到正在侦听连接的服务,则需要使用WcfCommunicationClient连接到它,您可以这样创建:

// Create binding
Binding binding = WcfUtility.CreateTcpClientBinding();
// Create a partition resolver
IServicePartitionResolver partitionResolver = ServicePartitionResolver.GetDefault();
// create a  WcfCommunicationClientFactory object.
var wcfClientFactory = new WcfCommunicationClientFactory<IMyService>
    (clientBinding: binding, servicePartitionResolver: partitionResolver);
var myServiceClient =  new WcfCommunicationClient(
    wcfClientFactory,
    ServiceUri,
    ServicePartitionKey.Singleton);

以上示例来自文档https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-wcf

因此,如果要使用ServiceProxy创建客户端,请更改服务以使用Fabric传输,或者将客户端更改为使用WcfCommunicationClient。