/// <summary>
        /// This method causes the communication listener to be opened. Once the Open
        ///             completes, the communication listener becomes usable - accepts and sends messages.
        /// </summary>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>
        /// A <see cref="T:System.Threading.Tasks.Task">Task</see> that represents outstanding operation. The result of the Task is
        ///             the endpoint string.
        /// </returns>
        public Task <string> OpenAsync(CancellationToken cancellationToken)
        {
            _wrappedCommunicationListener = new WcfCommunicationListener <ISubscriberService>(_serviceContext, _subscriberService,
                                                                                              CreateBinding(), EndpointResourceName);

            return(_wrappedCommunicationListener.OpenAsync(cancellationToken));
        }
示例#2
0
        void ActivateServiceType(Type serviceType)
        {
            //DESIGN NOTE:
            //Use the first manifest for initialization. For all Fabric-based interactions, ServiceContext sent in message updates context.
            ApplicationManifestAttribute[] manifests      = serviceType.GetCustomAttributes <ApplicationManifestAttribute>().ToArray();
            StatelessServiceContext        serviceContext = new StatelessServiceContext {
                ServiceName = new Uri("fabric:/" + manifests[0].ApplicationName + "/" + manifests[0].ServiceName)
            };

            StatelessService service = Activator.CreateInstance(serviceType, serviceContext) as StatelessService;

            foreach (ServiceInstanceListener instanceListener in service.ServiceInstanceListeners)
            {
                ICommunicationListener listener = instanceListener.CreateCommunicationListener(serviceContext);
                if (listener is WcfCommunicationListener)
                {
                    ActivateWcfService(serviceType, listener as WcfCommunicationListener);
                }
                else
                {
                    listener.OpenAsync(new System.Threading.CancellationToken()).Wait();
                    AppDomain.CurrentDomain.ProcessExit += delegate
                    {
                        try
                        {
                            listener.CloseAsync(new System.Threading.CancellationToken()).Wait();
                        }
                        catch
                        {}
                    };
                }
            }
        }
        private async Task <string> _OpenListener(
            ICommunicationListener listener,
            CancellationToken canceltoken)
        {
            string sAddress = await listener.OpenAsync(canceltoken);

            return(sAddress);
        }
        private async Task <string> _OpenListener(
            string ListenerName,
            ICommunicationListener listener,
            CancellationToken canceltoken)
        {
            this.statuses[ListenerName] = ICommunicationListenerStatus.Opening;
            string sAddress = await listener.OpenAsync(canceltoken);

            this.statuses[ListenerName] = ICommunicationListenerStatus.Opened;

            this.traceWriter.TraceMessage(string.Format("Composite listener - listener {0} opened on {1}", ListenerName, sAddress));

            return(sAddress);
        }
        private async Task<string> _OpenListener(
            string ListenerName,
            ICommunicationListener listener,
            CancellationToken canceltoken)
        {
            this.statuses[ListenerName] = ICommunicationListenerStatus.Opening;
            string sAddress = await listener.OpenAsync(canceltoken);
            this.statuses[ListenerName] = ICommunicationListenerStatus.Opened;

            this.traceWriter.TraceMessage(string.Format("Composite listener - listener {0} opened on {1}", ListenerName, sAddress));

            return sAddress;
        }
        private async Task<string> OpenListener(
            string listenerName,
            ICommunicationListener listener,
            CancellationToken canceltoken)
        {
            _statuses[listenerName] = CommunicationListenerStatus.Opening;
            var address = await listener.OpenAsync(canceltoken);
            _statuses[listenerName] = CommunicationListenerStatus.Opened;

            return address;
        }