Beispiel #1
0
        static T[] CreateChannelsFromMex <T>(Uri scope = null) where T : class
        {
            DuplexDiscoveryClient discoveryClient = new DuplexDiscoveryClient(Address.DiscoveryService);
            FindCriteria          criteria        = FindCriteria.CreateMetadataExchangeEndpointCriteria();

            FindResponse discovered = discoveryClient.Find(criteria);

            if (discovered.Endpoints.Count == 0)
            {
                return(new T[] {});
            }

            List <T> list = new List <T>();

            foreach (EndpointDiscoveryMetadata mexEndpoint in discovered.Endpoints)
            {
                ServiceEndpoint[] endpoints = MetadataHelper.GetEndpoints(mexEndpoint.Address.Uri.AbsoluteUri, typeof(T));
                foreach (ServiceEndpoint endpoint in endpoints)
                {
                    T proxy = ChannelFactory <T> .CreateChannel(endpoint.Binding, endpoint.Address);

                    list.Add(proxy);
                }
            }
            Debug.Assert(list.Count > 0);
            return(list.ToArray());
        }
Beispiel #2
0
        static T[] CreateInferedChannels <T>() where T : class
        {
            DuplexDiscoveryClient discoveryClient = new DuplexDiscoveryClient(Address.DiscoveryService);
            FindCriteria          criteria        = new FindCriteria(typeof(T));
            FindResponse          discovered      = discoveryClient.Find(criteria);

            if (discovered.Endpoints.Count == 0)
            {
                return(new T[] {});
            }
            List <T> list = new List <T>();

            foreach (EndpointDiscoveryMetadata endpoint in discovered.Endpoints)
            {
                Binding binding = ServiceModelEx.DiscoveryFactory.InferBindingFromUri(endpoint.Address.Uri);
                T       proxy   = ChannelFactory <T> .CreateChannel(binding, endpoint.Address);

                list.Add(proxy);
            }
            return(list.ToArray());
        }
Beispiel #3
0
        public static T CreateChannel <T>(Uri scope = null) where T : class
        {
            DuplexDiscoveryClient discoveryClient = new DuplexDiscoveryClient(Address.DiscoveryService);

            FindCriteria criteria = FindCriteria.CreateMetadataExchangeEndpointCriteria();

            criteria.MaxResults = 1;
            if (scope != null)
            {
                criteria.Scopes.Add(scope);
            }
            FindResponse discovered = discoveryClient.Find(criteria);

            Debug.Assert(discovered.Endpoints.Count == 1);
            Uri mexAddress = discovered.Endpoints[0].Address.Uri;

            ServiceEndpoint[] endpoints = MetadataHelper.GetEndpoints(mexAddress.AbsoluteUri, typeof(T));
            Debug.Assert(endpoints.Length == 1);

            Binding         binding = endpoints[0].Binding;
            EndpointAddress address = endpoints[0].Address;

            return(ChannelFactory <T> .CreateChannel(binding, address));
        }