Ejemplo n.º 1
0
            public void OnDiscoveryRequest(string contractName, string contractNamespace, Uri[] scopesToMatch)
            {
                IDiscoveryCallback callback = OperationContext.Current.GetCallbackChannel <IDiscoveryCallback>();

                foreach (ServiceEndpoint endpoint in Endpoints)
                {
                    if (endpoint.Contract.Name == contractName && endpoint.Contract.Namespace == contractNamespace)
                    {
                        Uri[] scopes = DiscoveryHelper.LookupScopes(endpoint);

                        if (scopesToMatch != null)
                        {
                            bool scopesMatched = true;
                            foreach (Uri scope in scopesToMatch)
                            {
                                if (scopes.Any(uri => uri.AbsoluteUri == scope.AbsoluteUri) == false)
                                {
                                    scopesMatched = false;
                                    break;
                                }
                            }
                            if (scopesMatched == false)
                            {
                                continue;
                            }
                        }

                        callback.OnDiscoveryResponse(endpoint.Address.Uri, contractName, contractNamespace, scopes);
                    }
                }
            }
Ejemplo n.º 2
0
        static void PublishAvailabilityEvent(ServiceEndpoint[] endpoints, Action <Uri, string, string, Uri[]> notification)
        {
            Action <ServiceEndpoint> notify = (endpoint) =>
            {
                if (endpoint is DiscoveryEndpoint || endpoint is ServiceMetadataEndpoint || endpoint.Contract.ContractType == typeof(IMetadataExchange))
                {
                    return;
                }
                Uri[] scopes = DiscoveryHelper.LookupScopes(endpoint);

                notification(endpoint.Address.Uri, endpoint.Contract.Name, endpoint.Contract.Namespace, scopes);
            };

            Action publish = () =>
            {
                try
                {
                    endpoints.ParallelForEach(notify);
                }
                catch
                {
                    Trace.WriteLine("Could not announce availability of service");
                }
                finally
                {
                    (notification.Target as ICommunicationObject).Close();
                }
            };

            Task.Run(publish);
        }
Ejemplo n.º 3
0
            void IServiceBusDiscovery.OnDiscoveryRequest(string contractName, string contractNamespace, Uri[] scopesToMatch, Uri responseAddress)
            {
                ChannelFactory <IServiceBusDiscoveryCallback> factory = new ChannelFactory <IServiceBusDiscoveryCallback>(DiscoveryResponseBinding, new EndpointAddress(responseAddress));

                factory.Endpoint.Behaviors.Add(Credentials);

                IServiceBusDiscoveryCallback callback = factory.CreateChannel();

                foreach (ServiceEndpoint endpoint in Endpoints)
                {
                    if (endpoint.Contract.Name == contractName && endpoint.Contract.Namespace == contractNamespace)
                    {
                        Uri[] scopes = DiscoveryHelper.LookupScopes(endpoint);

                        if (scopesToMatch != null)
                        {
                            bool scopesMatched = true;
                            foreach (Uri scope in scopesToMatch)
                            {
                                if (scopes.Any(uri => uri.AbsoluteUri == scope.AbsoluteUri) == false)
                                {
                                    scopesMatched = false;
                                    break;
                                }
                            }
                            if (scopesMatched == false)
                            {
                                continue;
                            }
                        }
                        try
                        {
                            callback.DiscoveryResponse(endpoint.Address.Uri, contractName, contractNamespace, scopes);
                        }
                        catch
                        {
                            callback = factory.CreateChannel();
                        }
                    }
                }
                (callback as ICommunicationObject).Close();
            }
        void PublishAvailabilityEvent(Action <Uri, string, string, Uri[]> notification)
        {
            foreach (ServiceEndpoint endpoint in Description.Endpoints)
            {
                if (endpoint is DiscoveryEndpoint || endpoint is ServiceMetadataEndpoint)
                {
                    continue;
                }
                Uri[] scopes = DiscoveryHelper.LookupScopes(endpoint);

                WaitCallback fire = delegate
                {
                    try
                    {
                        notification(endpoint.Address.Uri, endpoint.Contract.Name, endpoint.Contract.Namespace, scopes);
                        (notification.Target as ICommunicationObject).Close();
                    }
                    catch
                    {}
                };
                ThreadPool.QueueUserWorkItem(fire);
            }
        }