【问题标题】:Not able to find my stateless service that uses the WcfCommunicationListener找不到使用 WcfCommunicationListener 的无状态服务
【发布时间】:2017-01-17 06:26:07
【问题描述】:

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

【问题讨论】:

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


    【解决方案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 创建客户端,请将您的服务更改为使用结构传输,或者将您的客户端更改为使用 WcfCommunicationClient。

    【讨论】:

      猜你喜欢
      • 2016-12-12
      • 2012-08-17
      • 2020-07-10
      • 2014-07-04
      • 2020-02-29
      • 2011-02-05
      • 1970-01-01
      • 2016-03-25
      • 2017-05-23
      相关资源
      最近更新 更多