0

I am trying to find my stateless service using IServiceProxyFactory CreateServiceProxy method. It seems to find the service instance but when I invoke a method it gets an error "Client is trying to connect to invalid address net.tcp://localhost...". The stateless service uses WcfCommunicationListener.

alltej
  • 6,787
  • 10
  • 46
  • 87

1 Answers1

1

The default implementation of IServiceProxyFactory is ServiceProxyFactory, that creates an instance of FabricTransportServiceRemotingClientFactory which in turn gives you an FabricTransportServiceRemotingClient. This one communicates (as the name suggests) using Fabric transport over TCP. Fabric transport expects the Service to have a fabric transport listener FabricTransportServiceRemotingListener on a address like fabric:/applicationname/servicename.

If you want to connect to your service that is listening to connections using the WcfCommunicationListener then you need to connect to it using WcfCommunicationClient that you can create like this:

// 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);

The above sample is from the documentation https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-wcf

So, either change your service to use fabric transport if you want to use ServiceProxy to create a client, or change your client side to use WcfCommunicationClient instead.

yoape
  • 3,285
  • 1
  • 14
  • 27