public Scope(Type contract, M clientModel, AbstractChannelBuilder <M> builder, IWcfBurden burden)
 {
     this.contract    = contract ?? clientModel.Endpoint.Contract;
     this.clientModel = clientModel;
     this.builder     = builder;
     this.burden      = burden;
 }
        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);
            }
        }
        public override DiscoveryEndpoint GetDiscoveryEndpoint()
        {
            var forContract = DiscoveryVersion != null
                                ? new DiscoveryEndpoint(DiscoveryVersion, ServiceDiscoveryMode.Managed)
                                : new DiscoveryEndpoint();

            using (var discover = new DiscoveryClient(GetUdpDiscoveryEndpoint()))
            {
                var criteria = GetSearchCriteria(forContract.Contract.ContractType);
                RestrictDomain(criteria);

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

            return(null);
        }