예제 #1
0
        public IEndpoint CreateEndpoint(Uri requestedUri)
        {
            string scheme = requestedUri.Scheme.ToLowerInvariant();

            if (_transportFactories.Has(scheme))
            {
                ITransportFactory transportFactory = _transportFactories[scheme];
                try
                {
                    IEndpointAddress address = transportFactory.GetAddress(requestedUri);

                    var uriPath = new Uri(address.Uri.GetLeftPart(UriPartial.Path));
                    IEndpointBuilder builder = _endpointBuilders.Get(uriPath, key =>
                    {
                        var configurator = new EndpointConfigurator(address, _defaults);
                        return(configurator.CreateBuilder());
                    });

                    return(builder.CreateEndpoint(transportFactory));
                }
                catch (Exception ex)
                {
                    throw new EndpointException(requestedUri, "Failed to create endpoint", ex);
                }
            }

            throw new ConfigurationException(
                      "The {0} scheme was not handled by any registered transport.".FormatWith(requestedUri.Scheme));
        }