Пример #1
0
    Binding DiscoverBinding <T>()
    {
        Binding binding = null;

        DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
        FindResponse    discovered      = discoveryClient.Find(FindCriteria.CreateMexEndpointCriteria());

        foreach (EndpointDiscoveryMetadata mexEndpoint in discovered.Endpoints)
        {
            Debug.Assert(binding == null);

            ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IMyContract), mexEndpoint.Address.Uri, MetadataExchangeClientMode.MetadataExchange);
            Debug.Assert(endpoints.Count == 1);

            binding = endpoints[0].Binding;
        }
        return(binding);
    }
Пример #2
0
    T[] CreateChannelsFromMex <T>()
    {
        DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
        FindResponse    discovered      = discoveryClient.Find(FindCriteria.CreateMexEndpointCriteria());

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

        foreach (EndpointDiscoveryMetadata mexEndpoint in discovered.Endpoints)
        {
            ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IMyContract), mexEndpoint.Address.Uri, MetadataExchangeClientMode.MetadataExchange);
            foreach (ServiceEndpoint endpoint in endpoints)
            {
                T proxy = ChannelFactory <T> .CreateChannel(endpoint.Binding, endpoint.Address);

                list.Add(proxy);
            }
        }
        return(list.ToArray());
    }