Beispiel #1
1
        static EndpointAddress FindCalculatorServiceAddress()
        {
            // Create DiscoveryClient
            DiscoveryEndpoint discoveryEndpoint = new DiscoveryEndpoint(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8001/DiscoveryRouter/"));
            DiscoveryClient discoveryClient = new DiscoveryClient(discoveryEndpoint);

            Console.WriteLine("Finding ICalculatorService endpoints...");
            Console.WriteLine();

            // Find ICalculatorService endpoints            
            FindCriteria findCriteria = new FindCriteria(typeof(ICalculatorService));
            findCriteria.Duration = TimeSpan.FromSeconds(10);

            FindResponse findResponse = discoveryClient.Find(findCriteria);

            Console.WriteLine("Found {0} ICalculatorService endpoint(s).", findResponse.Endpoints.Count);
            Console.WriteLine();

            if (findResponse.Endpoints.Count > 0)
            {
                return findResponse.Endpoints[0].Address;
            }
            else
            {
                return null;
            }
        }
        internal FindCriteria Clone()
        {
            FindCriteria findCriteriaClone = new FindCriteria();

            foreach (Uri scope in this.Scopes)
            {
                findCriteriaClone.Scopes.Add(scope);
            }

            foreach (XmlQualifiedName contractTypeName in this.ContractTypeNames)
            {
                findCriteriaClone.ContractTypeNames.Add(new XmlQualifiedName(contractTypeName.Name, contractTypeName.Namespace));
            }

            foreach (XElement extension in this.Extensions)
            {
                findCriteriaClone.Extensions.Add(new XElement(extension));
            }

            findCriteriaClone.ScopeMatchBy = this.ScopeMatchBy;
            findCriteriaClone.Duration     = this.Duration;
            findCriteriaClone.MaxResults   = this.MaxResults;

            return(findCriteriaClone);
        }
 protected override IEnumerable<MatchedEndpointDiscoveryMetadata> OnMatchEndpoints(FindCriteria criteria)
 {
     return _endpoints
         .Where(meta => criteria.IsMatch(meta.Value))
         .Select(meta => new MatchedEndpointDiscoveryMetadata(meta.Value))
         .ToList();
 }
		private DiscoveryEndpoint DiscoverEndpoint(DiscoveryEndpoint endpoint, bool required)
		{
			using (var discover = new DiscoveryClient(UdpDiscoveryEndpoint ?? new UdpDiscoveryEndpoint()))
			{
				var criteria = new FindCriteria(endpoint.Contract.ContractType) { MaxResults = 1 };
				if (DiscoveryDuration.HasValue)
				{
					criteria.Duration = DiscoveryDuration.Value;
				}

				var discovered = discover.Find(criteria);
				if (discovered.Endpoints.Count > 0)
				{
					var endpointMetadata = discovered.Endpoints[0];
					var binding = Binding ?? AbstractChannelBuilder.GetBindingFromMetadata(endpointMetadata);
					return new DiscoveryEndpoint(binding, endpointMetadata.Address);
				}

				if (required)
				{
					throw new EndpointNotFoundException("Unable to locate a ServiceCatalog on the network.");
				}

				return null;
			}
		}
Beispiel #5
0
        public static MediaDevice[] GetAvailableMediaDevices()
        {
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint(DiscoveryVersion.WSDiscoveryApril2005));
            FindCriteria findCriteria = new FindCriteria
            {
                Duration = TimeSpan.FromSeconds(1),
                MaxResults = 15
            };

            findCriteria.ContractTypeNames.Add(new XmlQualifiedName("NetworkVideoTransmitter", @"http://www.onvif.org/ver10/network/wsdl"));

            FindResponse findResponse = discoveryClient.Find(findCriteria);

            List<MediaDevice> cameras = new List<MediaDevice>();

            foreach (var point in findResponse.Endpoints)
            {
                Uri uri = point.ListenUris.FirstOrDefault(u => u.HostNameType == UriHostNameType.IPv4);
                if (uri != null)
                {
                    string name = ONVIFAgent.GetDeviceInformation(uri);

                    cameras.Add(new MediaDevice(name, uri));
                }
            }
            return cameras.ToArray();
        }
Beispiel #6
0
        protected override IAsyncResult OnBeginOfflineAnnouncement(DiscoveryMessageSequence messageSequence, EndpointDiscoveryMetadata endpointDiscoveryMetadata, AsyncCallback callback, object state)
        {
            try
            {
                if (endpointDiscoveryMetadata == null)
                {
                    throw new ArgumentNullException("endpointDiscoveryMetadata");
                }

                // We care only about ISimpleChatService services
                FindCriteria criteria = new FindCriteria(typeof(ISimpleChatService));

                if (criteria.IsMatch(endpointDiscoveryMetadata))
                {
                    endpointDiscoveryMetadata.WriteLine("Removing");
                    Cache.Remove(endpointDiscoveryMetadata.Address.Uri);
                }
            }
            catch (KeyNotFoundException)
            {
                // No problem if it does not exist in the cache
            }

            return new CompletedAsyncResult(callback, state);
        }
        void Match(FindRequestContext findRequestContext)
        {
            FindCriteria criteria = findRequestContext.Criteria;

            if (!ScopeCompiler.IsSupportedMatchingRule(criteria.ScopeMatchBy))
            {
                return;
            }

            CompiledScopeCriteria[] compiledScopeCriterias = ScopeCompiler.CompileMatchCriteria(
                criteria.InternalScopes,
                criteria.ScopeMatchBy);

            int matchingEndpointCount = 0;

            for (int i = 0; i < this.publishedEndpoints.Count; i++)
            {
                if (criteria.IsMatch(this.publishedEndpoints[i], compiledScopeCriterias))
                {
                    findRequestContext.AddMatchingEndpoint(this.publishedEndpoints[i]);
                    matchingEndpointCount++;

                    if (matchingEndpointCount == criteria.MaxResults)
                    {
                        break;
                    }
                }
            }
        }
        public virtual EndpointDiscoveryMetadata[] FindEndpoints(FindCriteria criteria)
        {
			using (@lock.ForReading())
			{
				return MatchTargets(criteria).ToArray();
			}
        }
Beispiel #9
0
		protected FindRequestContext (FindCriteria criteria)
		{
			if (criteria == null)
				throw new ArgumentNullException ("criteria");
			Criteria = criteria;
			Endpoints = new Collection<EndpointDiscoveryMetadata> ();
		}
Beispiel #10
0
		public static FindCriteria CreateMetadataExchangeEndpointCriteria (IEnumerable<XmlQualifiedName> contractTypeNames)
		{
			var fc = new FindCriteria ();
			foreach (var type in contractTypeNames)
				fc.ContractTypeNames.Add (type);
			return fc;
		}
Beispiel #11
0
        public static LobbyWindow lanGame(UserAccount account, ILobbyGUI gui)
        {
            DiscoveryClient dc = new DiscoveryClient(new UdpDiscoveryEndpoint());
            FindCriteria fc = new FindCriteria(typeof(IDiscoveryTest));
            fc.Duration = TimeSpan.FromSeconds(5);
            FindResponse fr = dc.Find(fc);

            if (fr.Endpoints.Count > 0)
            {
                ip = fr.Endpoints[0].Address.Uri.Host.ToString();
            }
            else
            {
                string HostName = System.Net.Dns.GetHostName();
                System.Net.IPHostEntry hostInfo = System.Net.Dns.GetHostByName(HostName);
                string IpAdresse = hostInfo.AddressList[0].ToString();
                ip = IpAdresse;
                Server server = new Server(new WCFTCPServiceFactory(),ip);
                server.run();
            }

            factory = new WCFTCPConnectionFactory();
            lobbyWindow = new LobbyWindow(account, gui, factory);
            factory.connectToLobby(ip, lobbyWindow);

            return lobbyWindow;
        }
Beispiel #12
0
        public static void Main()
        {
            // Create DiscoveryClient
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

            Console.WriteLine("Finding ICalculatorService endpoints...");
            Console.WriteLine();

            // Find ICalculatorService endpoints
            FindCriteria findCriteria = new FindCriteria(typeof(ICalculatorService));
            findCriteria.Duration = TimeSpan.FromSeconds(5);

            FindResponse findResponse = discoveryClient.Find(findCriteria);

            Console.WriteLine("Found {0} ICalculatorService endpoint(s).", findResponse.Endpoints.Count);
            Console.WriteLine();

            // Check to see if endpoints were found & print the XML metadata in them.
            if (findResponse.Endpoints.Count > 0)
            {
                foreach (XElement xElement in findResponse.Endpoints[0].Extensions)
                {
                    Console.WriteLine("Printing Metadata from ServiceEndpoint:");
                    Console.WriteLine("Endpoint Information: " + xElement.Element("Information").Value);
                    Console.WriteLine("Endpoint Started at Time: " + xElement.Element("Time").Value);
                    Console.WriteLine();
                }
                InvokeCalculatorService(findResponse.Endpoints[0].Address);
            }
            Console.WriteLine("Press <ENTER> to exit.");
            Console.ReadLine();
        }
Beispiel #13
0
        static EndpointAddress FindCalculatorServiceAddress()
        {
            // Create a discovery client using the secure endpoint that applies and checks the compact signature
            DiscoveryClient discoveryClient = new DiscoveryClient("udpSecureDiscoveryEndpoint");

            Console.WriteLine("Finding ICalculatorService endpoints...");
            Console.WriteLine();

            FindCriteria findCriteria = new FindCriteria(typeof(ICalculatorService));
            findCriteria.Duration = TimeSpan.FromSeconds(5);

            // Find ICalculatorService endpoints
            FindResponse findResponse = discoveryClient.Find(findCriteria);

            Console.WriteLine("Found {0} ICalculatorService endpoint(s).", findResponse.Endpoints.Count);
            Console.WriteLine();
            if (findResponse.Endpoints.Count > 0)
            {
                return findResponse.Endpoints[0].Address;
            }
            else
            {
                return null;
            }
        }
Beispiel #14
0
        static EndpointAddress FindCalculatorServiceAddress()
        {
            // Create DiscoveryClient
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

            // Find ICalculatorService endpoints in the specified scope            
            Uri scope = new Uri("ldap:///ou=engineering,o=exampleorg,c=us");
            FindCriteria findCriteria = new FindCriteria(typeof(ICalculatorService));
            findCriteria.Scopes.Add(scope);
            findCriteria.MaxResults = 1;

            Console.WriteLine("Finding ICalculatorService endpoints within {0} scope...", scope);
            Console.WriteLine();
            
            FindResponse findResponse = discoveryClient.Find(findCriteria);

            Console.WriteLine("Found {0} ICalculatorService endpoint(s).", findResponse.Endpoints.Count);
            Console.WriteLine();

            if (findResponse.Endpoints.Count > 0)
            {
                return findResponse.Endpoints[0].Address;
            }
            else
            {
                return null;
            }
        }
 public FindRequestResponseContext(
     FindCriteria criteria,
     ProbeRequestResponseAsyncResult <TProbeMessage, TResponseMessage> probeRequestResponseAsyncResult)
     : base(criteria)
 {
     this.matchingEndpoints = new Collection <EndpointDiscoveryMetadata>();
     this.probeRequestResponseAsyncResult = probeRequestResponseAsyncResult;
 }
Beispiel #16
0
		public DynamicEndpoint (ContractDescription contract, Binding binding)
			: base (contract, binding, new EndpointAddress ("http://schemas.microsoft.com/discovery/dynamic"))
		{
			if (binding == null)
				throw new ArgumentNullException ("binding");
			DiscoveryEndpointProvider = new UdpDiscoveryEndpointProvider ();
			FindCriteria = new FindCriteria (contract.ContractType);
		}
        public static FindCriteria CreateMetadataExchangeEndpointCriteria(Type contractType)
        {
            FindCriteria criteria = CreateMetadataExchangeEndpointCriteria();

            criteria.Scopes.Add(GetContractTypeNameScope(GetContractTypeName(contractType)));

            return(criteria);
        }
 public DiscoveryClientDuplexChannel(
     ChannelManagerBase channelManagerBase,
     IChannelFactory <TChannel> innerChannelFactory,
     FindCriteria findCriteria,
     DiscoveryEndpointProvider discoveryEndpointProvider)
     : base(channelManagerBase, innerChannelFactory, findCriteria, discoveryEndpointProvider)
 {
 }
        public static FindCriteria CreateMetadataExchangeEndpointCriteria()
        {
            FindCriteria criteria = new FindCriteria();

            criteria.ContractTypeNames.Add(EndpointDiscoveryMetadata.MetadataContractName);

            return(criteria);
        }
 public DiscoveryClientRequestSessionChannel(
     ChannelManagerBase channelManagerBase,
     IChannelFactory <IRequestSessionChannel> innerChannelFactory,
     FindCriteria findCriteria,
     DiscoveryEndpointProvider discoveryEndpointProvider)
     : base(channelManagerBase, innerChannelFactory, findCriteria, discoveryEndpointProvider)
 {
 }
Beispiel #21
0
		public void DefaultValues ()
		{
			var fc = new FindCriteria ();
			Assert.AreEqual (int.MaxValue, fc.MaxResults, "#1");
			Assert.IsNotNull (fc.ContractTypeNames, "#2");
			Assert.IsNotNull (fc.Scopes, "#3");
			Assert.AreEqual (FindCriteria.ScopeMatchByPrefix, fc.ScopeMatchBy, "#4");
			Assert.AreEqual (TimeSpan.FromSeconds (20), fc.Duration, "#5");
		}
		private void RestrictDomain(FindCriteria criteria)
		{
			if (string.IsNullOrEmpty(Domain) == false)
			{
				var domain = new WcfDiscoveryDomain(Domain);
				criteria.Scopes.AddAll(domain.Scopes);
				criteria.Extensions.AddAll(domain.Extensions);
			}
		}
Beispiel #23
0
 protected FindRequestContext(FindCriteria criteria)
 {
     if (criteria == null)
     {
         throw new ArgumentNullException("criteria");
     }
     Criteria  = criteria;
     Endpoints = new Collection <EndpointDiscoveryMetadata> ();
 }
Beispiel #24
0
		public DynamicEndpoint (ContractDescription contract, Binding binding)
			: base (contract, CreateBinding (binding), new EndpointAddress ("http://schemas.microsoft.com/discovery/dynamic"))
		{
			if (binding == null)
				throw new ArgumentNullException ("binding");
			DiscoveryEndpointProvider = DiscoveryEndpointProvider.CreateDefault ();
			FindCriteria = new FindCriteria (contract.ContractType);
			
			IsSystemEndpoint = true;
		}
        public static FindCriteria CreateMetadataExchangeEndpointCriteria(IEnumerable <XmlQualifiedName> contractTypeNames)
        {
            var fc = new FindCriteria();

            foreach (var type in contractTypeNames)
            {
                fc.ContractTypeNames.Add(type);
            }
            return(fc);
        }
        public DiscoveryClientChannelFactory(IChannelFactory <TChannel> innerChannelFactory, FindCriteria findCriteria, DiscoveryEndpointProvider discoveryEndpointProvider)
        {
            Fx.Assert(findCriteria != null, "The findCriteria must be non null.");
            Fx.Assert(discoveryEndpointProvider != null, "The discoveryEndpointProvider must be non null.");
            Fx.Assert(innerChannelFactory != null, "The innerChannelFactory must be non null.");

            this.findCriteria = findCriteria;
            this.discoveryEndpointProvider = discoveryEndpointProvider;
            this.innerChannelFactory       = innerChannelFactory;
        }
Beispiel #27
0
 public EndpointAddress FindNotifierServiceAddress(int secondsTimeout)
 {
     DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
     FindCriteria criteria = new FindCriteria(typeof(INotifierService)) { Duration = new TimeSpan(0, 0, 0, secondsTimeout) };
     FindResponse findResponse = discoveryClient.Find(criteria);
     if (findResponse.Endpoints.Count > 0)
     {
         return findResponse.Endpoints[0].Address;
     }
     return null;
 }
Beispiel #28
0
        public DynamicEndpoint(ContractDescription contract, Binding binding)
            : base(contract, CreateBinding(binding), new EndpointAddress("http://schemas.microsoft.com/discovery/dynamic"))
        {
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }
            DiscoveryEndpointProvider = DiscoveryEndpointProvider.CreateDefault();
            FindCriteria = new FindCriteria(contract.ContractType);

            IsSystemEndpoint = true;
        }
        /// <summary>
        /// Starts this instance.
        /// </summary>
        public void Start()
        {
            findCriteria = new FindCriteria(typeof(IAgent))
            {
                Scopes = { connectionsHostOptions.Scope },
                Duration = TimeSpan.FromMilliseconds(options.DiscoveryIntervalInMiliseconds)
            };
            discoveryClient = GetInitilizedDisoveryClient();
            log.Info("Starting clients tracking");

            Discover();
        }
Beispiel #30
0
        private void OnOfflineAnnouncement(object sender, AnnouncementEventArgs e)
        {
            EndpointDiscoveryMetadata metadata =
                e.EndpointDiscoveryMetadata;

            FindCriteria criteria =
                new FindCriteria(typeof(ISimpleChatService));

            if (criteria.IsMatch(metadata))
            {
                this.RemoveUser(metadata.Address.Uri);
            }
        }
        static void AddContractTypeScopes(EndpointDiscoveryMetadata endpointDiscoveryMetadata, ServiceDescription serviceDescription)
        {
            foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints)
            {
                if (IsMetadataEndpoint(endpoint) || IsDiscoverySystemEndpoint(endpoint))
                {
                    continue;
                }

                endpointDiscoveryMetadata.Scopes.Add(FindCriteria.GetContractTypeNameScope(
                                                         new XmlQualifiedName(endpoint.Contract.Name, endpoint.Contract.Namespace)));
            }
        }
 public EndpointDiscoveryMetadata MatchEndpoint(FindCriteria criteria)
 {
     EndpointDiscoveryMetadata endpoint = null;
     var endpoints = OnMatchEndpoints(criteria);
     var metadatas = new List<EndpointDiscoveryMetadata>();
     foreach (var ep in endpoints)
     {
         var metadata = ep.ToEndpointDiscoveryMetadata();
         metadatas.Add(metadata);
     }
     endpoint = _endpointSelector.Select(metadatas);
     return endpoint;
 }
Beispiel #33
0
        public DiscoveryClientBindingElement(DiscoveryEndpointProvider discoveryEndpointProvider, FindCriteria findCriteria)
        {
            if (discoveryEndpointProvider == null)
            {
                throw new ArgumentNullException("discoveryEndpointProvider");
            }
            if (findCriteria == null)
            {
                throw new ArgumentNullException("findCriteria");
            }

            DiscoveryEndpointProvider = discoveryEndpointProvider;
            FindCriteria = findCriteria;
        }
Beispiel #34
0
        static void FindCalculatorServiceAddress()
        {
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

            discoveryClient.FindCompleted += new EventHandler<FindCompletedEventArgs>(ClientFindCompleted);
            discoveryClient.FindProgressChanged += new EventHandler<FindProgressChangedEventArgs>(ClientFindProgressChanged);

            Console.WriteLine("Finding ICalculatorServices endpoints asynchronously...\n");
            FindCriteria findCriteria = new FindCriteria(typeof(ICalculatorService));
            findCriteria.Duration = TimeSpan.FromSeconds(5);

            // Find ICalculatorService endpoint asynchronously. The results are returned asynchronously via events            
            discoveryClient.FindAsync(findCriteria);
        }
Beispiel #35
0
 public Collection<EndpointDiscoveryMetadata> GetAvailableConnections()
 {
     FindCriteria criteria = new FindCriteria(ContractType);
     criteria.Duration = FindDuration;
     Collection<EndpointDiscoveryMetadata> endpoints = new Collection<EndpointDiscoveryMetadata>();
     FindResponse response = ClientDiscovery.Find(criteria);
     if (response.Endpoints.Count > 0)
         for (Int32 index = 0; index < response.Endpoints.Count; index++)
         {
             String[] allowedClients = GetAllowedClients(response.Endpoints[index]);
             if (IsConnectionAllowed(allowedClients))
                 endpoints.Add(response.Endpoints[index]);
         }
     return endpoints;
 }
Beispiel #36
0
        public DiscoveryClientBindingElement(DiscoveryEndpointProvider discoveryEndpointProvider, FindCriteria findCriteria)
        {
            if (discoveryEndpointProvider == null)
            {
                throw FxTrace.Exception.ArgumentNull("discoveryEndpointProvider");
            }

            if (findCriteria == null)
            {
                throw FxTrace.Exception.ArgumentNull("findCriteria");
            }

            this.findCriteria = findCriteria;
            this.discoveryEndpointProvider = discoveryEndpointProvider;
        }
Beispiel #37
0
        public void FindAsync(FindCriteria criteria, object userState)
        {
            AsyncCallback cb = delegate(IAsyncResult result) {
                FindResponse ret   = null;
                Exception    error = null;
                try {
                    ret = EndFind(result);
                } catch (Exception ex) {
                    error = ex;
                }
                OnFindCompleted(new FindCompletedEventArgs(ret, error, cancelled, result.AsyncState));
            };

            cancelled = false;
            BeginFind(criteria, cb, userState);
        }
Beispiel #38
0
 public static Uri WcfTestClient_DiscoverChannel()
 {
     var dc = new DiscoveryClient(new UdpDiscoveryEndpoint());
     FindCriteria fc = new FindCriteria(typeof(IWcfPingTest));
     fc.Duration = TimeSpan.FromSeconds(20);
     FindResponse fr = dc.Find(fc);
     foreach (EndpointDiscoveryMetadata edm in fr.Endpoints)
     {
         Console.WriteLine("uri found = " + edm.Address.Uri.ToString());
     }
     // here is the really nasty part
     // i am just returning the first channel, but it may not work.
     // you have to do some logic to decide which uri to use from the discovered uris
     // for example, you may discover "127.0.0.1", but that one is obviously useless.
     // also, catch exceptions when no endpoints are found and try again.
     return fr.Endpoints[0].Address.Uri;
 }
Beispiel #39
0
        private void OnOnlineAnnouncement(object sender, AnnouncementEventArgs e)
        {
            EndpointDiscoveryMetadata metadata =
                e.EndpointDiscoveryMetadata;

            // We are looking for services that 
            // implement the ISimpleChatService contract
            FindCriteria criteria =
                new FindCriteria(typeof(ISimpleChatService));

            if (criteria.IsMatch(metadata))
            {
                if (this.GetUser(metadata.Address.Uri) == null)
                {
                    this.PopulateUserList(metadata);
                }
            }
        }
Beispiel #40
0
        static void Main(string[] args)
        {
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
            FindCriteria criteria = new FindCriteria(typeof(ICalculator));
            criteria.Scopes.Add(new Uri("http://www.artech.com/"));
            FindResponse response = discoveryClient.Find(criteria);

            if (response.Endpoints.Count > 0)
            {
                EndpointAddress address = response.Endpoints[0].Address;
                using (ChannelFactory<ICalculator> channelFactory = new ChannelFactory<ICalculator>(new WS2007HttpBinding(), address))
                {
                    ICalculator calculator = channelFactory.CreateChannel();
                    Console.WriteLine("x + y = {2} when x = {0} and y = {1}", 1, 2, calculator.Add(1, 2));
                }
            }
            Console.Read();
        }
Beispiel #41
0
        protected override void Execute(CodeActivityContext context)
        {
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

            FindCriteria findCriteria = new FindCriteria();
            // Create a contract to add to the findCriteria. The search will be based on this contract.
            findCriteria.ContractTypeNames.Add(new XmlQualifiedName("IPrintService", "http://tempuri.org/"));
            findCriteria.MaxResults = 1;
            findCriteria.Duration = new TimeSpan(0, 0, 0, 3);

            FindResponse findResponse = discoveryClient.Find(findCriteria);
            discoveryClient.Close();

            if (findResponse.Endpoints.Count == 0)
            {
                throw new EndpointNotFoundException("Client was unable to find any matching endpoints using Discovery.");
            }

            this.DiscoveredEndpointUri.Set(context, findResponse.Endpoints[0].Address.Uri);
        }
Beispiel #42
0
        protected override IAsyncResult OnBeginOnlineAnnouncement(DiscoveryMessageSequence messageSequence,
                                                EndpointDiscoveryMetadata endpointDiscoveryMetadata,
                                                AsyncCallback callback,
                                                object state)
        {
            if (endpointDiscoveryMetadata == null)
            {
                throw new ArgumentNullException("endpointDiscoveryMetadata");
            }

            // We care only about ISimpleChatService services
            FindCriteria criteria = new FindCriteria(typeof(ISimpleChatService));

            if (criteria.IsMatch(endpointDiscoveryMetadata))
            {
                endpointDiscoveryMetadata.WriteLine("Adding");
                Cache.Add(endpointDiscoveryMetadata);
            }

            return new CompletedAsyncResult(callback, state);
        }
Beispiel #43
0
        static void Main(string[] args)
        {
            var discovery = new DiscoveryClient(
                new UdpDiscoveryEndpoint());
            var criteria = new FindCriteria(typeof(EchoService))
            {
                Duration = TimeSpan.FromSeconds(2)
            };
            var service = discovery.Find(criteria);
            foreach (var endpoint in service.Endpoints)
            {
                Console.WriteLine("{0}", endpoint.Address);
            }

            var channelFactory =
                new ChannelFactory<EchoService>(
                    new BasicHttpBinding(),
                    service.Endpoints.FirstOrDefault().Address);
            var response = channelFactory.CreateChannel().Echo("hello!");
            Console.WriteLine(response);
        }
        public static FindCriteria CreateMetadataExchangeEndpointCriteria(IEnumerable <XmlQualifiedName> contractTypeNames)
        {
            if (contractTypeNames == null)
            {
                throw FxTrace.Exception.ArgumentNull("contractTypeNames");
            }

            FindCriteria criteria = CreateMetadataExchangeEndpointCriteria();

            foreach (XmlQualifiedName item in contractTypeNames)
            {
                if (item == null)
                {
                    throw FxTrace.Exception.ArgumentNull("item");
                }

                criteria.Scopes.Add(GetContractTypeNameScope(item));
            }

            return(criteria);
        }
        public DiscoveryClientChannelBase(
            ChannelManagerBase channelManagerBase,
            IChannelFactory <TChannel> innerChannelFactory,
            FindCriteria findCriteria,
            DiscoveryEndpointProvider discoveryEndpointProvider)
            : base(channelManagerBase)
        {
            Fx.Assert(findCriteria != null, "The findCriteria must be non null.");
            Fx.Assert(discoveryEndpointProvider != null, "The discoveryEndpointProvider must be non null.");
            Fx.Assert(innerChannelFactory != null, "The innerChannelFactory must be non null.");

            this.innerChannelFactory       = innerChannelFactory;
            this.findCriteria              = findCriteria;
            this.discoveryEndpointProvider = discoveryEndpointProvider;

            this.discoveredEndpoints      = new InputQueue <EndpointDiscoveryMetadata>();
            this.totalExpectedEndpoints   = int.MaxValue;
            this.totalDiscoveredEndpoints = 0;
            this.discoveryCompleted       = false;
            this.thisLock = new object();
        }
        void Cleanup(TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            Exception     exception     = null;

            lock (this.thisLock)
            {
                this.discoveryCompleted = true;
            }

            try
            {
                this.discoveryClient.CancelAsync(this);
                ((ICommunicationObject)this.discoveryClient).Close(timeoutHelper.RemainingTime());
            }
            catch (TimeoutException timeoutException)
            {
                exception = timeoutException;
            }
            catch (CommunicationException communicationException)
            {
                exception = communicationException;
            }
            finally
            {
                if (exception != null && TD.DiscoveryClientInClientChannelFailedToCloseIsEnabled())
                {
                    TD.DiscoveryClientInClientChannelFailedToClose(exception);
                }
            }

            this.discoveredEndpoints.Dispose();

            this.discoveryClient           = null;
            this.discoveredEndpoints       = null;
            this.findCriteria              = null;
            this.discoveryEndpointProvider = null;
            this.innerChannelFactory       = null;
        }
Beispiel #47
0
        public static void Main()
        {
            // Create DiscoveryClient
            DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());

            Console.WriteLine("Finding ICalculatorService endpoints...");
            Console.WriteLine();

            FindCriteria findCriteria = new FindCriteria(typeof(ICalculatorService));
            findCriteria.Duration = TimeSpan.FromSeconds(5);

            // Find ICalculatorService endpoints            
            FindResponse findResponse = discoveryClient.Find(findCriteria);

            Console.WriteLine("Found {0} ICalculatorService endpoint(s).", findResponse.Endpoints.Count);
            Console.WriteLine();

            // Check to see if endpoints were found
            if (findResponse.Endpoints.Count > 0)
            {
                EndpointDiscoveryMetadata discoveredEndpoint = findResponse.Endpoints[0];

                // Check to see if the endpoint has a listenUri and if it differs from the Address URI
                if (discoveredEndpoint.ListenUris.Count > 0 && discoveredEndpoint.Address.Uri != discoveredEndpoint.ListenUris[0])
                {
                    // Since the service is using a unique ListenUri, it needs to be invoked at the correct ListenUri 
                    InvokeCalculatorService(discoveredEndpoint.Address, discoveredEndpoint.ListenUris[0]);
                }
                else
                {
                    // Endpoint was found, however it doesn't have a unique ListenUri, hence invoke the service with only the Address URI
                    InvokeCalculatorService(discoveredEndpoint.Address, null);
                }
            }

            Console.WriteLine("Press <ENTER> to exit.");
            Console.ReadLine();
        }
Beispiel #48
0
        public Collection<EndpointDiscoveryMetadata> GetAvailableConnections()
        {
            FindCriteria findCriteria = new FindCriteria(m_ContractType);
            findCriteria.Duration = m_FindDuration;
            Collection<EndpointDiscoveryMetadata> endpoints = new Collection<EndpointDiscoveryMetadata>();

            FindResponse findResponse = m_DiscoveryClient.Find(findCriteria);

            if (findResponse.Endpoints.Count > 0)
            {
                for (Int32 index = 0; index < findResponse.Endpoints.Count; index++)
                {
                    String[] AllowedClients = GetAllowedClients(findResponse.Endpoints[index]);

                    if (IsConnectionAllowed(AllowedClients))
                    {
                        endpoints.Add(findResponse.Endpoints[index]);
                    }
                }
            }

            return endpoints;
        }
        protected FindRequestContext(FindCriteria criteria)
        {
            Fx.Assert(criteria != null, "The criteria must be non null.");

            this.criteria = criteria;
        }
 public void FindAsync(FindCriteria criteria)
 {
     FindAsync(criteria, null);
 }
 IAsyncResult BeginFind(FindCriteria criteria, AsyncCallback callback, object state)
 {
     return(((IDiscoveryCommon)client).BeginFind(criteria, callback, state));
 }
Beispiel #52
0
 public DefaultFindRequestContext(FindCriteria criteria)
     : base(criteria)
 {
 }
Beispiel #53
0
 private DiscoveryClientBindingElement(DiscoveryClientBindingElement elementToBeCloned)
     : base(elementToBeCloned)
 {
     this.discoveryEndpointProvider = elementToBeCloned.DiscoveryEndpointProvider;
     this.findCriteria = elementToBeCloned.FindCriteria.Clone();;
 }
Beispiel #54
0
 protected virtual IAsyncResult BeginShouldRedirectFind(FindCriteria resolveCriteria, AsyncCallback callback, object state)
 {
     return(new CompletedAsyncResult <bool>(false, callback, state));
 }
Beispiel #55
0
        //-----------------------------------------------------
        //  Redirect Adhoc to Managed Probe
        //-----------------------------------------------------

        #region ShouldRedirectFind

        // Summary:
        //     Override this method to allow the discovery proxy to send out multicast suppression
        //     messages when it receives a multicast find request.
        //
        // Parameters:
        //   resolveCriteria:
        //     The resolve criteria that describes the service to find.
        //
        //   callback:
        //     The callback delegate to call when the operation has completed.
        //
        //   state:
        //     The user-defined state data.
        //
        // Returns:
        //     A reference to the pending asynchronous operation.
        protected override IAsyncResult BeginShouldRedirectFind(FindCriteria resolveCriteria, AsyncCallback callback, object state)
        {
            return(_findTaskFactory.Create(resolveCriteria).ToApm(callback, state));
        }
 protected virtual IAsyncResult BeginShouldRedirectFind(FindCriteria resolveCriteria, AsyncCallback callback, Object state)
 {
     throw new NotImplementedException();
 }
Beispiel #57
0
 public DuplexFindContext(FindCriteria criteria, ProbeDuplexAsyncResult <TProbeMessage, TResponseChannel> probeDuplexAsyncResult)
     : base(criteria)
 {
     this.matchingEndpoints      = new InputQueue <EndpointDiscoveryMetadata>();
     this.probeDuplexAsyncResult = probeDuplexAsyncResult;
 }
Beispiel #58
0
 IAsyncResult IMulticastSuppressionImplementation.BeginShouldRedirectFind(FindCriteria findCriteria, AsyncCallback callback, object state)
 {
     return(this.BeginShouldRedirectFind(findCriteria, callback, state));
 }
Beispiel #59
0
 public DiscoveryClientBindingElement()
 {
     DiscoveryEndpointProvider = DiscoveryEndpointProvider.CreateDefault();
     FindCriteria = new FindCriteria();              // empty
 }
        internal static FindCriteria ReadXml(XmlReader reader, DiscoveryVersion version)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            var ret = new FindCriteria();

            reader.MoveToContent();
            if (!reader.IsStartElement("Probe", version.Namespace) || reader.IsEmptyElement)
            {
                throw new XmlException(String.Format("Non-empty ProbeType element is expected. Got '{0}' {1} node in namespace '{2}' instead.", reader.LocalName, reader.NodeType, reader.NamespaceURI));
            }
            reader.ReadStartElement("Probe", version.Namespace);

            // standard members
            reader.MoveToContent();
            if (reader.IsStartElement("Types", version.Namespace))
            {
                ret.ContractTypeNames = new Collection <XmlQualifiedName> ((XmlQualifiedName [])reader.ReadElementContentAs(typeof(XmlQualifiedName []), null, "Types", version.Namespace));
            }

            reader.MoveToContent();
            if (reader.IsStartElement("Types", version.Namespace))
            {
                if (reader.MoveToAttribute("MatchBy"))
                {
                    ret.ScopeMatchBy = new Uri(reader.Value, UriKind.RelativeOrAbsolute);
                    reader.MoveToElement();
                }
            }
            if (reader.IsStartElement("Scopes", version.Namespace))
            {
                ret.Scopes = new Collection <Uri> ((Uri [])reader.ReadElementContentAs(typeof(Uri []), null, "Scopes", version.Namespace));
            }

            // non-standard members
            for (reader.MoveToContent(); !reader.EOF && reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent())
            {
                if (reader.NamespaceURI == SerializationNS)
                {
                    switch (reader.LocalName)
                    {
                    case "MaxResults":
                        ret.MaxResults = reader.ReadElementContentAsInt();
                        break;

                    case "Duration":
                        ret.Duration = (TimeSpan)reader.ReadElementContentAs(typeof(TimeSpan), null);
                        break;
                    }
                }
                else
                {
                    ret.Extensions.Add(XElement.Load(reader));
                }
            }

            reader.ReadEndElement();

            return(ret);
        }