private IServiceRemotingRequestMessageHeader CreateServiceRemotingRequestMessageHeader(
            ServiceRemotingDispatchHeaders serviceRemotingDispatchHeaders)
        {
            InterfaceDetails details;

            if (ServiceCodeBuilder.TryGetKnownTypes(serviceRemotingDispatchHeaders.ServiceInterfaceName, out details))
            {
                var headers = new ServiceRemotingRequestMessageHeader();
                headers.InterfaceId = details.Id;
                var headersMethodId = 0;
                if (details.MethodNames.TryGetValue(serviceRemotingDispatchHeaders.MethodName, out headersMethodId))
                {
                    headers.MethodId = headersMethodId;
                }
                else
                {
                    throw new NotSupportedException("This Method is not Supported" +
                                                    serviceRemotingDispatchHeaders.MethodName);
                }

                return(headers);
            }
            throw new NotSupportedException("This Interface is not Supported" +
                                            serviceRemotingDispatchHeaders.ServiceInterfaceName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Instantiates the ServiceRemotingDispatcher that uses the given service context and
        /// dispatches messages to the given service implementation.
        /// </summary>
        /// <param name="serviceContext">Service context</param>
        /// <param name="service">Service implementation that implements interfaces of type <see cref="IService"/></param>
        public ServiceRemotingDispatcher(ServiceContext serviceContext, IService service)
        {
            Requires.ThrowIfNull(serviceContext, "serviceContext");

            this.cancellationHelper = new ServiceRemotingCancellationHelper(serviceContext.TraceId);

            this.methodDispatcherMap = new Dictionary <int, ServiceMethodDispatcherBase>();
            this.service             = service;

            if (service != null)
            {
                var serviceTypeInformation = ServiceTypeInformation.Get(service.GetType());
                List <ServiceInterfaceDescription> interfaceDescriptions = new List <ServiceInterfaceDescription>();

                foreach (var interfaceType in serviceTypeInformation.InterfaceTypes)
                {
                    var methodDispatcher = ServiceCodeBuilder.GetOrCreateMethodDispatcher(interfaceType);
                    this.methodDispatcherMap.Add(methodDispatcher.InterfaceId, methodDispatcher);
                    interfaceDescriptions.Add(ServiceInterfaceDescription.Create(interfaceType));
                }

                this.servicePerformanceCounterProvider =
                    new ServicePerformanceCounterProvider(serviceContext.PartitionId,
                                                          serviceContext.ReplicaOrInstanceId,
                                                          interfaceDescriptions);
            }
        }
        internal virtual InterfaceDetails GetInterfaceDetails(int interfaceId)
        {
            InterfaceDetails interfaceDetails;

            if (!ServiceCodeBuilder.TryGetKnownTypes(interfaceId, out interfaceDetails))
            {
                throw new ArgumentException("No interface found with this Id  " + interfaceId);
            }
            return(interfaceDetails);
        }
Exemplo n.º 4
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));
        }
        /// <summary>
        /// Create a proxy to the actor service that is hosting the specified actor id and implementing specified type of the service interface.
        /// </summary>
        /// <typeparam name="TServiceInterface">The service interface implemented by the actor service.</typeparam>
        /// <param name="serviceUri">Uri of the actor service to connect to.</param>
        /// <param name="partitionKey">The key of the actor service partition to connect to.</param>
        /// <param name="listenerName">
        /// By default an actor service has only one listener for clients to connect to and communicate with.
        /// However it is possible to configure an actor service with more than one listeners, the listenerName parameter specifies the name of the listener to connect to.
        /// </param>
        /// <returns>A service proxy object that implements <see cref="Microsoft.ServiceFabric.Services.Remoting.Client.IServiceProxy"/> and TServiceInterface.</returns>
        public TServiceInterface CreateActorServiceProxy <TServiceInterface>(
            Uri serviceUri,
            long partitionKey,
            string listenerName = null) where TServiceInterface : IService
        {
            var serviceInterfaceType           = typeof(TServiceInterface);
            var proxyGenerator                 = ServiceCodeBuilder.GetOrCreateProxyGenerator(serviceInterfaceType);
            var serviceRemotingPartitionClient = new ServiceRemotingPartitionClient(
                this.GetOrCreateServiceRemotingClientFactory(serviceInterfaceType),
                serviceUri,
                new ServicePartitionKey(partitionKey),
                TargetReplicaSelector.Default,
                listenerName,
                this.retrySettings);

            return((TServiceInterface)(object)proxyGenerator.CreateServiceProxy(serviceRemotingPartitionClient));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Instantiates the ServiceRemotingDispatcher that uses the given service context and
        /// dispatches messages to the given service implementation.
        /// </summary>
        /// <param name="serviceContext">Service context</param>
        /// <param name="service">Service implementation that implements interfaces of type <see cref="IService"/></param>
        public ServiceRemotingDispatcher(ServiceContext serviceContext, IService service)
        {
            Requires.ThrowIfNull(serviceContext, "serviceContext");

            this.cancellationHelper = new ServiceRemotingCancellationHelper(serviceContext.TraceId);

            this.methodDispatcherMap = new Dictionary <int, ServiceMethodDispatcherBase>();
            this.service             = service;

            if (service != null)
            {
                var serviceTypeInformation = ServiceTypeInformation.Get(service.GetType());
                foreach (var interfaceType in serviceTypeInformation.InterfaceTypes)
                {
                    var methodDispatcher = ServiceCodeBuilder.GetOrCreateMethodDispatcher(interfaceType);
                    this.methodDispatcherMap.Add(methodDispatcher.InterfaceId, methodDispatcher);
                }
            }
        }
        private void Initialize(ServiceContext serviceContext, object serviceImplementation,
                                IEnumerable <Type> remotedInterfaces, bool nonServiceInterface,
                                IServiceRemotingMessageBodyFactory serviceRemotingMessageBodyFactory)
        {
            this.serviceRemotingMessageBodyFactory = serviceRemotingMessageBodyFactory ?? new DataContractRemotingMessageFactory();

            this.cancellationHelper = new ServiceRemotingCancellationHelper(serviceContext.TraceId);

            this.methodDispatcherMap   = new Dictionary <int, MethodDispatcherBase>();
            this.serviceImplementation = serviceImplementation;

            if (serviceImplementation != null)
            {
                var interfaceDescriptions = new List <ServiceInterfaceDescription>();
                foreach (var interfaceType in remotedInterfaces)
                {
                    MethodDispatcherBase methodDispatcher;
                    if (nonServiceInterface)
                    {
                        methodDispatcher = ServiceCodeBuilder.GetOrCreateMethodDispatcherForNonMarkerInterface(interfaceType);
                        interfaceDescriptions.Add(ServiceInterfaceDescription.CreateUsingCRCId(interfaceType, false));
                    }
                    else
                    {
                        methodDispatcher = ServiceCodeBuilder.GetOrCreateMethodDispatcher(interfaceType);
                        interfaceDescriptions.Add(ServiceInterfaceDescription.CreateUsingCRCId(interfaceType, true));
                    }
                    this.methodDispatcherMap.Add(methodDispatcher.InterfaceId, methodDispatcher);
                }

                this.servicePerformanceCounterProvider =
                    new ServicePerformanceCounterProvider(serviceContext.PartitionId,
                                                          serviceContext.ReplicaOrInstanceId,
                                                          interfaceDescriptions,
                                                          false);
            }
        }