Example #1
0
 /// <summary>
 /// Creates an <see cref="ServiceProxy"/>
 /// </summary>
 /// <typeparam name="TServiceInterface">The type of service to create</typeparam>
 /// <param name="serviceUri">The uri of the service</param>
 /// <param name="customHeaders">A <see cref="CustomHeaders"/> instance with data passed to the service</param>
 /// <param name="partitionKey"></param>
 /// <param name="targetReplicaSelector"></param>
 /// <param name="listenerName"></param>
 /// <returns>A service proxy object that implements IServiceProxy and TServiceInterface.</returns>
 public static TServiceInterface Create <TServiceInterface>(Uri serviceUri, CustomHeaders customHeaders = null,
                                                            ServicePartitionKey partitionKey            = null,
                                                            TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default, string listenerName = null)
     where TServiceInterface : IService
 {
     return(Create <TServiceInterface>(serviceUri, () => customHeaders, partitionKey, targetReplicaSelector, listenerName));
 }
Example #2
0
 private IStore CreateStoreProxy(TargetReplicaSelector targetReplicaSelector)
 {
     // The matchmaking service only store the matchmaking members in a single partition.
     return(ServiceProxy.Create <IStore>(
                new Uri("fabric:/SFKV/SFKV.Store"),
                new ServicePartitionKey(0),
                targetReplicaSelector));
 }
 public ValidationServiceClient(
     ICommunicationClientFactory <WcfCommunicationClient <IValidationServiceStateful> > communicationClientFactory,
     Uri serviceUri, ServicePartitionKey partitionKey = null,
     TargetReplicaSelector targetReplicaSelector      = TargetReplicaSelector.Default, string listenerName = null,
     OperationRetrySettings retrySettings             = null) : base(communicationClientFactory, serviceUri, partitionKey,
                                                                     targetReplicaSelector, listenerName, retrySettings)
 {
 }
Example #4
0
 public static TServiceInterface CreateServiceProxy <TServiceInterface>(
     Uri serviceUri,
     ServicePartitionKey partitionKey            = null,
     TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default,
     string listenerName = null)
     where TServiceInterface : IService
 {
     return(DefaultServiceProxyFactory.CreateServiceProxy <TServiceInterface>(serviceUri, partitionKey, targetReplicaSelector, listenerName));
 }
Example #5
0
        public async Task <IServiceRemotingClient> GetClientAsync(ResolvedServicePartition previousRsp,
                                                                  TargetReplicaSelector targetReplicaSelector,
                                                                  string listenerName,
                                                                  OperationRetrySettings retrySettings,
                                                                  CancellationToken cancellationToken)
        {
            var client = await serviceRemotingClientFactory.GetClientAsync(previousRsp, targetReplicaSelector, listenerName, retrySettings, cancellationToken);

            return(new ServiceRemotingClientWrapper(client, traceId));
        }
 /// <summary>
 /// Re-resolves a partition of the specified service containing one or more communication listeners and returns a client to communicate
 /// to the endpoint corresponding to the given listenerName.
 /// The endpoint of the service is of the form - {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}
 /// </summary>
 /// <param name="previousRsp">Previous ResolvedServicePartition value</param>
 /// <param name="targetReplicaSelector">Specifies which replica in the partition identified by the partition key, the client should connect to</param>
 /// <param name="listenerName">Specifies which listener in the endpoint of the chosen replica, to which the client should connect to</param>
 /// <param name="retrySettings">Specifies the retry policy that should be used for exceptions that occur when creating the client.</param>
 /// <param name="cancellationToken">Cancellation token</param>
 /// <returns>
 /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result of the Task is
 /// the CommunicationClient(<see cref="ICommunicationClient" />) object.
 /// </returns>
 public async Task <IServiceRemotingClient> GetClientAsync(ResolvedServicePartition previousRsp,
                                                           TargetReplicaSelector targetReplicaSelector,
                                                           string listenerName, OperationRetrySettings retrySettings, CancellationToken cancellationToken)
 {
     return(await this.clientFactoryImpl.GetClientAsync(previousRsp,
                                                        targetReplicaSelector,
                                                        listenerName,
                                                        retrySettings,
                                                        cancellationToken));
 }
Example #7
0
 public MockActorProxy(
     ActorId actorId,
     Uri serviceUri,
     ServicePartitionKey partitionKey,
     TargetReplicaSelector replicaSelector,
     string listenerName,
     ICommunicationClientFactory <IServiceRemotingClient> factory)
 {
     ActorId = actorId;
     ActorServicePartitionClient = new MockActorServicePartitionClient(actorId, serviceUri, partitionKey, replicaSelector, listenerName, factory);
 }
        public async Task <IServiceRemotingClient> GetClientAsync(
            ResolvedServicePartition previousRsp,
            TargetReplicaSelector targetReplicaSelector,
            string listenerName,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            var client = await this._wrapped.GetClientAsync(previousRsp, targetReplicaSelector, listenerName, retrySettings, cancellationToken);

            return(new CustomServiceRemotingClient(client));
        }
 /// <summary>
 /// Resolves a partition of the specified service containing one or more communication listeners and returns a client to communicate
 /// to the endpoint corresponding to the given listenerName.
 /// The endpoint of the service is of the form - {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}
 /// </summary>
 /// <param name="serviceUri">Uri of the service to resolve</param>
 /// <param name="partitionKey">Key that identifies the partition to resolve</param>
 /// <param name="targetReplicaSelector">Specifies which replica in the partition identified by the partition key, the client should connect to</param>
 /// <param name="listenerName">Specifies which listener in the endpoint of the chosen replica, to which the client should connect to</param>
 /// <param name="retrySettings">Specifies the retry policy that should be used for exceptions that occur when creating the client.</param>
 /// <param name="cancellationToken">Cancellation token</param>
 /// <returns>
 /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result of the Task is
 /// the CommunicationClient(<see cref="ICommunicationClient" />) object.
 /// </returns>
 public async Task <IServiceRemotingClient> GetClientAsync(Uri serviceUri, ServicePartitionKey partitionKey,
                                                           TargetReplicaSelector targetReplicaSelector,
                                                           string listenerName, OperationRetrySettings retrySettings, CancellationToken cancellationToken)
 {
     return(await this.clientFactoryImpl.GetClientAsync(serviceUri,
                                                        partitionKey,
                                                        targetReplicaSelector,
                                                        listenerName,
                                                        retrySettings,
                                                        cancellationToken));
 }
Example #10
0
        /// <summary>
        /// Creates a proxy to communicate to the specified service using the remoted interface TServiceInterface that
        /// the service implements.
        /// <typeparam name="TServiceInterface">Interface that is being remoted</typeparam>
        /// <param name="serviceUri">Uri of the Service.</param>
        /// <param name="partitionKey">The Partition key that determines which service partition is responsible for handling requests from this service proxy</param>
        /// <param name="targetReplicaSelector">Determines which replica or instance of the service partition the client should connect to.</param>
        /// <param name="listenerName">This parameter is Optional if the service has a single communication listener. The endpoints from the service
        /// are of the form {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}. When the service exposes multiple endpoints, this parameter
        /// identifies which of those endpoints to use for the remoting communication.
        /// </param>
        /// <returns>The proxy that implement the interface that is being remoted. The returned object also implement <see cref="IServiceProxy"/> interface.</returns>
        /// </summary>
        public TServiceInterface CreateNonIServiceProxy <TServiceInterface>(
            Uri serviceUri,
            ServicePartitionKey partitionKey            = null,
            TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default,
            string listenerName = null)
        {
            var serviceInterfaceType = typeof(TServiceInterface);
            var proxyGenerator       = ServiceCodeBuilder.GetOrCreateProxyGeneratorForNonServiceInterface(serviceInterfaceType);

            return(this.CreateServiceProxy <TServiceInterface>(serviceUri, partitionKey, targetReplicaSelector, listenerName, serviceInterfaceType, proxyGenerator));
        }
Example #11
0
        public static TServiceInterface CreateServiceProxy <TServiceInterface>(
            Uri serviceUri,
            ServicePartitionKey partitionKey            = null,
            TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default,
            string listenerName = null,
            Action <CallSummary> raiseSummary = null,
            string remoteServiceName          = null) where TServiceInterface : IService
        {
            var proxyFactory = new CorrelatingServiceProxyFactory <TServiceInterface>(raiseSummary: raiseSummary, remoteServiceName: remoteServiceName);

            return(proxyFactory.CreateServiceProxy <TServiceInterface>(serviceUri, partitionKey, targetReplicaSelector, listenerName));
        }
Example #12
0
        public async Task <IServiceRemotingClient> GetClientAsync(
            Uri serviceUri,
            ServicePartitionKey partitionKey,
            TargetReplicaSelector targetReplicaSelector,
            string listenerName,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            IServiceRemotingClient innerClient = await innerClientFactory.GetClientAsync(serviceUri, partitionKey, targetReplicaSelector, listenerName, retrySettings, cancellationToken).ConfigureAwait(false);

            return(new CorrelatingServiceRemotingClient(innerClient, serviceUri, methodNameProvider));
        }
Example #13
0
        public TServiceInterface CreateServiceProxy <TServiceInterface>(Uri serviceUri,
                                                                        ServicePartitionKey partitionKey            = null,
                                                                        TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default, string listenerName = null)
            where TServiceInterface : IService
        {
            MockServiceProxy serviceProxy = new MockServiceProxy();

            serviceProxy.Supports <TServiceInterface>((mockUri) => mockServiceLookupTable[serviceUri]);

            return(serviceProxy.Create <TServiceInterface>(serviceUri, partitionKey, targetReplicaSelector,
                                                           listenerName));
        }
        public async Task <IServiceRemotingClient> GetClientAsync(
            Uri serviceUri,
            ServicePartitionKey partitionKey,
            TargetReplicaSelector targetReplicaSelector,
            string listenerName,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            var client = await this._wrapped.GetClientAsync(serviceUri, partitionKey, targetReplicaSelector, listenerName, retrySettings, cancellationToken);

            return(new CustomServiceRemotingClient(client));
        }
        public TServiceInterface CreateServiceProxy <TServiceInterface>(
            Uri serviceUri,
            ServicePartitionKey partitionKey            = null,
            TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default,
            string listenerName = null
            ) where TServiceInterface : IService
        {
            GetOrDiscoverServiceMethodDispatcher(typeof(TServiceInterface));
            var proxy = GetInnerServiceProxyFactory(typeof(TServiceInterface)).CreateServiceProxy <TServiceInterface>(serviceUri, partitionKey, targetReplicaSelector, listenerName);

            UpdateRequestContext(serviceUri);
            return(proxy);
        }
        public static TServiceInterface Create <TServiceInterface>(
            Uri serviceUri, ServicePartitionKey partitionKey = null, TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default,
            string listenerName = null) where TServiceInterface : IService
        {
            var proxyFactory = new CorrelatingServiceProxyFactory(callbackClient =>
                                                                  new FabricTransportServiceRemotingClientFactory(callbackClient: callbackClient));

            TServiceInterface proxy =
                proxyFactory.CreateServiceProxy <TServiceInterface>(serviceUri, partitionKey, targetReplicaSelector,
                                                                    listenerName);

            return(proxy);
        }
        public static T Create <T>(
            Uri serviceUri,
            TelemetryClient telemetryClient,
            ServiceContext context,
            ServicePartitionKey partitionKey            = null,
            TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default) where T : class, IService
        {
            var service = CreateFactory().CreateServiceProxy <T>(serviceUri, partitionKey, targetReplicaSelector);
            T   proxy   = Generator.CreateInterfaceProxyWithTargetInterface(
                service,
                new LoggingServiceProxyInterceptor(telemetryClient, context, serviceUri.ToString()));

            return(proxy);
        }
Example #18
0
        /// <summary>
        /// Creates an <see cref="ServiceProxy"/>
        /// </summary>
        /// <typeparam name="TServiceInterface">The type of service to create</typeparam>
        /// <param name="serviceUri">The uri of the service</param>
        /// <param name="customHeaderProvider">A factory to create a <see cref="CustomHeaders"/> instance with data passed to the service</param>
        /// <param name="partitionKey"></param>
        /// <param name="targetReplicaSelector"></param>
        /// <param name="listenerName"></param>
        /// <returns>A service proxy object that implements IServiceProxy and TServiceInterface.</returns>
        public static TServiceInterface Create <TServiceInterface>(Uri serviceUri, Func <CustomHeaders> customHeaderProvider,
                                                                   ServicePartitionKey partitionKey            = null,
                                                                   TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default, string listenerName = null)
            where TServiceInterface : IService
        {
            var methodNameProvider = new MethodNameProvider();

            var proxyFactory = new ServiceProxyFactory(handler =>
                                                       new ExtendedServiceRemotingClientFactory(
                                                           new FabricTransportServiceRemotingClientFactory(remotingCallbackMessageHandler: handler), customHeaderProvider, methodNameProvider));
            var proxy = proxyFactory.CreateServiceProxy <TServiceInterface>(serviceUri, partitionKey, targetReplicaSelector, listenerName);

            methodNameProvider.AddMethodsForProxyOrService(proxy.GetType().GetInterfaces(), typeof(IService));
            return(proxy);
        }
Example #19
0
 internal MockActorServicePartitionClient(
     ActorId actorId,
     Uri serviceUri,
     ServicePartitionKey partitionKey,
     TargetReplicaSelector replicaSelector,
     string listenerName,
     ICommunicationClientFactory <IServiceRemotingClient> factory)
 {
     ActorId               = actorId;
     ServiceUri            = serviceUri;
     PartitionKey          = partitionKey;
     TargetReplicaSelector = replicaSelector;
     ListenerName          = listenerName;
     Factory               = factory;
 }
 public ServiceRemotingPartitionClient(
     IServiceRemotingClientFactory remotingClientFactory,
     Uri serviceUri,
     ServicePartitionKey partitionKey            = null,
     TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default,
     string listenerName = null,
     OperationRetrySettings retrySettings = null)
     : base(
         remotingClientFactory,
         serviceUri,
         partitionKey,
         targetReplicaSelector,
         listenerName,
         retrySettings)
 {
 }
        public async Task <IServiceRemotingClient> GetClientAsync(
            ResolvedServicePartition previousRsp,
            TargetReplicaSelector targetReplicaSelector,
            string listenerName,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            var client = await _InnerClientFactory.GetClientAsync(
                previousRsp,
                targetReplicaSelector,
                listenerName,
                retrySettings,
                cancellationToken).ConfigureAwait(false);

            return(new TrackingFabricTransportServiceRemotingClient(client));
        }
        public async Task <IServiceRemotingClient> GetClientAsync(
            ResolvedServicePartition previousRsp,
            TargetReplicaSelector targetReplicaSelector,
            string listenerName,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            var client = await serviceRemotingClientFactory.GetClientAsync(
                previousRsp,
                targetReplicaSelector,
                listenerName,
                retrySettings,
                cancellationToken);

            return(new ServiceRemotingClientWrapper(client, customHeadersProvider, BeforeSendRequestResponseAsync, AfterSendRequestResponseAsync));
        }
Example #23
0
        public async Task <IServiceRemotingClient> GetClientAsync(
            ResolvedServicePartition previousRsp,
            TargetReplicaSelector targetReplicaSelector,
            string listenerName,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            IServiceRemotingClient inner = await _inner.GetClientAsync(
                previousRsp,
                targetReplicaSelector,
                listenerName,
                retrySettings,
                cancellationToken);

            return(new ActivityServiceRemotingClient(inner));
        }
        /// <summary>
        /// Re-resolves a partition of the specified service containing one or more communication listeners and returns a client to communicate
        /// to the endpoint corresponding to the given listenerName.
        /// The endpoint of the service is of the form - {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}
        /// </summary>
        /// <param name="previousRsp">Previous ResolvedServicePartition value</param>
        /// <param name="targetReplicaSelector">Specifies which replica in the partition identified by the partition key, the client should connect to</param>
        /// <param name="listenerName">Specifies which listener in the endpoint of the chosen replica, to which the client should connect to</param>
        /// <param name="retrySettings">Specifies the retry policy that should be used for exceptions that occur when creating the client.</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>
        /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result of the Task is
        /// the CommunicationClient(<see cref="ICommunicationClient" />) object.
        /// </returns>
        async Task <IServiceRemotingClient> ICommunicationClientFactory <IServiceRemotingClient> .GetClientAsync(
            ResolvedServicePartition previousRsp,
            TargetReplicaSelector targetReplicaSelector,
            string listenerName,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            var client = await this.impl.GetClientAsync(
                previousRsp,
                targetReplicaSelector,
                listenerName,
                retrySettings,
                cancellationToken);

            return(client);
        }
Example #25
0
        /// <summary>
        /// Creates a proxy  to communicate to the specified service using the remoted interface TServiceInterface that
        /// the service implements.
        /// <typeparam name="TServiceInterface">Interface that is being remoted . Service Interface does not need to be inherited from IService.</typeparam>
        /// <param name="serviceUri">Uri of the Service.</param>
        /// <param name="partitionKey">The Partition key that determines which service partition is responsible for handling requests from this service proxy</param>
        /// <param name="targetReplicaSelector">Determines which replica or instance of the service partition the client should connect to.</param>
        /// <param name="listenerName">This parameter is Optional if the service has a single communication listener. The endpoints from the service
        /// are of the form {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}. When the service exposes multiple endpoints, this parameter
        /// identifies which of those endpoints to use for the remoting communication.
        /// </param>
        /// <returns>The proxy that implement the interface that is being remoted. The returned object also implement <see cref="IServiceProxy"/> interface.</returns>
        /// </summary>
        public TServiceInterface CreateNonIServiceProxy <TServiceInterface>(Uri serviceUri,
                                                                            ServicePartitionKey partitionKey            = null,
                                                                            TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default, string listenerName = null)
        {
            var serviceInterfaceType = typeof(TServiceInterface);

            if (this.proxyFactoryV2 == null)
            {
                var provider = this.GetProviderAttribute(serviceInterfaceType);

                this.proxyFactoryV2 = new V2.Client.ServiceProxyFactory(provider.CreateServiceRemotingClientFactoryV2, retrySettings);
            }
            return(this.proxyFactoryV2.CreateNonIServiceProxy <TServiceInterface>(serviceUri,
                                                                                  partitionKey,
                                                                                  targetReplicaSelector,
                                                                                  listenerName));
        }
Example #26
0
        /// <summary>
        /// Re-resolves a partition of the specified service containing one or more communication listeners and returns a client to communicate
        /// to the endpoint corresponding to the given listenerName.
        ///
        /// The endpoint of the service is of the form - {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}
        /// </summary>
        /// <param name="previousRsp">Previous ResolvedServicePartition value</param>
        /// <param name="targetReplicaSelector">Specifies which replica in the partition identified by the partition key, the client should connect to</param>
        /// <param name="listenerName">Specifies which listener in the endpoint of the chosen replica, to which the client should connect to</param>
        /// <param name="retrySettings">Specifies the retry policy that should be used for exceptions that occur when creating the client.</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>
        /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result of the Task is
        /// the CommunicationClient(<see cref="ICommunicationClient" />) object.
        /// </returns>
        async Task <IServiceRemotingClient> ICommunicationClientFactory <IServiceRemotingClient> .GetClientAsync(
            ResolvedServicePartition previousRsp,
            TargetReplicaSelector targetReplicaSelector,
            string listenerName,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            var wcfClient = await this.wcfFactory.GetClientAsync(
                previousRsp,
                targetReplicaSelector,
                listenerName,
                retrySettings,
                cancellationToken);

            return(new WcfServiceRemotingClient(wcfClient,
                                                this.serializersManager));
        }
Example #27
0
        /// <summary>
        /// Gets or Creates the CommunicationClient for the specified listener name by resolving based on the given previousRsp.
        /// </summary>
        /// <param name="previousRsp">Previous ResolvedServicePartition value</param>
        /// <param name="targetReplica">Specifies which replica in the partition identified by the partition key, the client should connect to</param>
        /// <param name="listenerName">Specifies which listener in the endpoint of the chosen replica, to which the client should connect to</param>
        /// <param name="retrySettings">Specifies the retry policy that should be used for exceptions that occur when creating the client.</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>
        /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result of the Task is
        /// the CommunicationClient(<see cref="ICommunicationClient" />) object.
        /// </returns>
        public async Task <TCommunicationClient> GetClientAsync(
            ResolvedServicePartition previousRsp,
            TargetReplicaSelector targetReplica,
            string listenerName,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            var newClient = await this.CreateClientWithRetriesAsync(
                previousRsp,
                targetReplica,
                listenerName,
                retrySettings,
                true,
                cancellationToken);

            return(newClient);
        }
Example #28
0
        private TServiceInterface CreateServiceProxy <TServiceInterface>(Uri serviceUri, ServicePartitionKey partitionKey,
                                                                         TargetReplicaSelector targetReplicaSelector, string listenerName, Type serviceInterfaceType,
                                                                         ServiceProxyGenerator proxyGenerator)
        {
            var clientFactory = this.GetOrCreateServiceRemotingClientFactory(serviceInterfaceType);
            var serviceRemotingPartitionClient = new ServiceRemotingPartitionClient(
                clientFactory,
                serviceUri,
                partitionKey,
                targetReplicaSelector,
                listenerName,
                this.retrySettings);


            return((TServiceInterface)(object)proxyGenerator.CreateServiceProxy(serviceRemotingPartitionClient,
                                                                                clientFactory.GetRemotingMessageBodyFactory()
                                                                                ));
        }
        /// <summary>
        /// Resolves a partition of the specified service containing one or more communication listeners and returns a client to communicate
        /// to the endpoint corresponding to the given listenerName.
        /// The endpoint of the service is of the form - {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}
        /// </summary>
        /// <param name="serviceUri">Uri of the service to resolve</param>
        /// <param name="partitionKey">Key that identifies the partition to resolve</param>
        /// <param name="targetReplicaSelector">Specifies which replica in the partition identified by the partition key, the client should connect to</param>
        /// <param name="listenerName">Specifies which listener in the endpoint of the chosen replica, to which the client should connect to</param>
        /// <param name="retrySettings">Specifies the retry policy that should be used for exceptions that occur when creating the client.</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>
        /// A <see cref="System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result of the Task is
        /// the CommunicationClient(<see cref="ICommunicationClient" />) object.
        /// </returns>
        async Task <IServiceRemotingClient> ICommunicationClientFactory <IServiceRemotingClient> .GetClientAsync(
            Uri serviceUri,
            ServicePartitionKey partitionKey,
            TargetReplicaSelector targetReplicaSelector,
            string listenerName,
            OperationRetrySettings retrySettings,
            CancellationToken cancellationToken)
        {
            var client = await this.impl.GetClientAsync(
                serviceUri,
                partitionKey,
                targetReplicaSelector,
                listenerName,
                retrySettings,
                cancellationToken);

            return(client);
        }
        /// <summary>
        /// Creates a proxy to communicate to the specified service using the remoted interface TServiceInterface that
        /// the service implements.
        /// <typeparam name="TServiceInterface">Interface that is being remoted</typeparam>
        /// <param name="serviceUri">Uri of the Service.</param>
        /// <param name="partitionKey">The Partition key that determines which service partition is responsible for handling requests from this service proxy</param>
        /// <param name="targetReplicaSelector">Determines which replica or instance of the service partition the client should connect to.</param>
        /// <param name="listenerName">This parameter is Optional if the service has a single communication listener. The endpoints from the service
        /// are of the form {"Endpoints":{"Listener1":"Endpoint1","Listener2":"Endpoint2" ...}}. When the service exposes multiple endpoints, this parameter
        /// identifies which of those endpoints to use for the remoting communication.
        /// </param>
        /// <returns>The proxy that implement the interface that is being remoted. The returned object also implement <see cref="Microsoft.ServiceFabric.Services.Remoting.Client.IServiceProxy"/> interface.</returns>
        /// </summary>
        public TServiceInterface CreateServiceProxy <TServiceInterface>(
            Uri serviceUri,
            ServicePartitionKey partitionKey            = null,
            TargetReplicaSelector targetReplicaSelector = TargetReplicaSelector.Default,
            string listenerName = null) where TServiceInterface : IService
        {
            var serviceInterfaceType           = typeof(TServiceInterface);
            var proxyGenerator                 = ServiceCodeBuilder.GetOrCreateProxyGenerator(serviceInterfaceType);
            var serviceRemotingPartitionClient = new ServiceRemotingPartitionClient(
                this.GetOrCreateServiceRemotingClientFactory(serviceInterfaceType),
                serviceUri,
                partitionKey,
                targetReplicaSelector,
                listenerName,
                this.retrySettings);

            return((TServiceInterface)(object)proxyGenerator.CreateServiceProxy(serviceRemotingPartitionClient));
        }