private void ProbeInitialServices(ServiceHost serviceHost) { var probe = new DiscoveryClient(UdpDiscoveryEndpoint ?? new UdpDiscoveryEndpoint()); probe.FindProgressChanged += (_, args) => RegisterService(serviceHost, args.EndpointDiscoveryMetadata); probe.FindCompleted += (_, args) => probe.Close(); probe.FindAsync(ProbeCriteria ?? new FindCriteria()); }
/// <summary> /// Starts a discovery process /// </summary> public void Find( DiscoveryType type = DiscoveryType.WsDiscovery ) { ActivityServices.Clear(); #if !ANDROID switch ( type ) { case DiscoveryType.WsDiscovery: using ( var wsBrowser = new DiscoveryClient( new UdpDiscoveryEndpoint() ) ) { wsBrowser.FindProgressChanged += WsBrowserFindProgressChanged; wsBrowser.FindCompleted += WsBrowserFindCompleted; wsBrowser.FindAsync( new FindCriteria( typeof( IDiscovery ) ) ); } break; case DiscoveryType.Zeroconf: { var zcBrowser = new ServiceBrowser(); zcBrowser.ServiceAdded += zcBrowser_ServiceAdded; zcBrowser.Browse( "_am._tcp", "local" ); } break; } #else Probe(); #endif }
/// <summary> /// Starts a discovery process /// </summary> public void Find(DiscoveryType type = DiscoveryType.WSDiscovery) { ActivityServices.Clear(); #if !ANDROID switch (type) { case DiscoveryType.WSDiscovery: using (var wsBrowser = new DiscoveryClient(new UdpDiscoveryEndpoint())) { wsBrowser.FindProgressChanged += WSBrowserFindProgressChanged; wsBrowser.FindCompleted += WSBrowserFindCompleted; wsBrowser.FindAsync(new FindCriteria(typeof(IDiscovery))); } break; case DiscoveryType.Zeroconf: { var zcBrowser = new ServiceBrowser(); zcBrowser.ServiceAdded += delegate(object o, ServiceBrowseEventArgs args) { args.Service.Resolved += ZcBrowserServiceResolved; args.Service.Resolve(); }; zcBrowser.Browse("_am._tcp", "local"); } break; } switch (type) { case DiscoveryType.WSDiscovery: using (var wsBrowser = new DiscoveryClient(new UdpDiscoveryEndpoint())) { wsBrowser.FindProgressChanged += WSBrowserFindProgressChanged; wsBrowser.FindCompleted += WSBrowserFindCompleted; wsBrowser.FindAsync(new FindCriteria(typeof(IDiscovery))); } break; case DiscoveryType.Zeroconf: { var zcBrowser = new ServiceBrowser(); zcBrowser.ServiceAdded += delegate(object o, ServiceBrowseEventArgs args) { args.Service.Resolved += ZcBrowserServiceResolved; args.Service.Resolve(); }; zcBrowser.Browse("_am._tcp", "local"); } break; } #else Probe(); #endif }
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); }
void findEvo() { try { using (var discovery = new DiscoveryClient(new UdpDiscoveryEndpoint())) { discovery.FindProgressChanged += (s, e) => { try { if (null != e.EndpointDiscoveryMetadata) { var port = e.EndpointDiscoveryMetadata.Address.Uri.Port; var host = e.EndpointDiscoveryMetadata.Address.Uri.DnsSafeHost; lock (_discoveryLock) { if (null == evoServers.FirstOrDefault(u=>u.DnsSafeHost == host && u.Port == port ) ) evoServers = evoServers.Concat(new[] { e.EndpointDiscoveryMetadata.Address.Uri }).ToArray(); } discoveryCompleted = true; } } catch (Exception ex) { var t = ex.Message; } }; discovery.FindAsync(new FindCriteria(typeof(com.labizbille.evoSDK.IEVOService_v1))); } } catch (Exception ex) { Debug.WriteLine("Failed to discover EVO servers : " + ex.Message); } finally { discoveryCompleted = true; } }
private void RefreshTopology(object state) { // heartbeat - will remove any failing nodes Parallel.ForEach(topologyState.Keys, FindEndpointMetadata); var discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint()); discoveryClient.FindProgressChanged += DiscoveryClientOnFindProgressChanged; discoveryClient.FindCompleted += DiscoveryClientOnFindCompleted; discoveryClient.FindAsync(new FindCriteria(typeof(INodeStateService)), state); }