コード例 #1
0
ファイル: DiscoveryFactory.cs プロジェクト: eraj2587/NSB7
            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);
                    }
                }
            }
コード例 #2
0
ファイル: DiscoveryService.cs プロジェクト: eraj2587/NSB7
        void IDiscovery.OnDiscoveryRequest(string contractName, string contractNamespace, Uri[] scopesToMatch)
        {
            if (m_Addresses.Count == 0)
            {
                return;
            }
            //Callback to the client wanting to discover
            IDiscoveryCallback clientCallback  = OperationContext.Current.GetCallbackChannel <IDiscoveryCallback>();
            DiscoveryCallback  serviceCallback = new DiscoveryCallback(clientCallback);

            Action <string> discover = (address) =>
            {
                IDiscovery serviceProxy = DuplexChannelFactory <IDiscovery, IDiscoveryCallback> .CreateChannel(serviceCallback, DiscoveryFactory.Binding, new EndpointAddress(address as string));

                CancellationTokenSource cancellationSource = new CancellationTokenSource();
                EventHandler            cleanup            = delegate
                {
                    //Will still be Opening if service was not found and the discovery period expires.
                    ICommunicationObject proxy = serviceProxy as ICommunicationObject;
                    if (proxy.State != CommunicationState.Faulted)
                    {
                        try
                        {
                            proxy.Close();
                        }
                        catch
                        {}
                    }
                    cancellationSource.Cancel();
                };
                (clientCallback as ICommunicationObject).Closed  += cleanup;
                (clientCallback as ICommunicationObject).Faulted += cleanup;
                Task.Delay(DiscoveryFactory.Binding.SendTimeout).ContinueWith(_ => cleanup(null, EventArgs.Empty), cancellationSource.Token);

                try
                {
                    serviceProxy.OnDiscoveryRequest(contractName, contractNamespace, scopesToMatch);
                }
                catch
                {
                    Trace.Write("Some problem occurred publishing to a service.");
                }
            };

            m_Addresses.ForEachAsync(discover);
        }
コード例 #3
0
ファイル: DiscoveryService.cs プロジェクト: eraj2587/NSB7
 public DiscoveryCallback(IDiscoveryCallback discoveryCallback)
 {
     m_DiscoveryCallback = discoveryCallback;
 }
 public LoggerDiscovery(IDiscoveryCallback cb)
 {
     MaxConnectionCount = 100;
     _discoveryCallback = cb;
     _semaphore         = new Semaphore(MaxConnectionCount, MaxConnectionCount);
 }