我正在尝试使用IServiceProxyFactory
CreateServiceProxy
方法找到我的无状态服务。它似乎找到了服务实例,但是当我调用一个方法时,它会收到一个错误"Client is trying to connect to invalid address net.tcp://localhost..."
。无状态服务使用WcfCommunicationListener。
答案 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);
因此,如果要使用ServiceProxy创建客户端,请更改服务以使用Fabric传输,或者将客户端更改为使用WcfCommunicationClient。