我正在尝试使用IServiceProxyFactory
CreateServiceProxy
方法找到我的无状态服务。它似乎找到了服务实例,但是当我调用一个方法时它得到一个错误"Client is trying to connect to invalid address net.tcp://localhost..."
。无状态服务使用 WcfCommunicationListener。
1 回答
1
的默认实现IServiceProxyFactory
是ServiceProxyFactory
,它创建一个实例,FabricTransportServiceRemotingClientFactory
然后给你一个FabricTransportServiceRemotingClient
. 这个通过 TCP 使用 Fabric 传输进行通信(顾名思义)。Fabric 传输期望服务FabricTransportServiceRemotingListener
在地址上具有结构传输侦听器,例如fabric:/applicationname/servicename
.
如果您想使用 连接到正在侦听连接的服务,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);
因此,如果您想使用 ServiceProxy 创建客户端,请将您的服务更改为使用结构传输,或者将您的客户端更改为使用 WcfCommunicationClient。
于 2017-01-16T22:26:07.960 回答