private async Task <Stream> DownloadSchemaImportAsync(Uri schemaUri, CancellationToken cancellationToken)
        {
            MetadataExchangeResolver metadataExchangeResolver = MetadataExchangeResolver.Create(
                new EndpointAddress(schemaUri),
                _httpCredentialsProvider?.Clone() as IHttpCredentialsProvider,
                _clientCertificatesProvider?.Clone() as IClientCertificateProvider,
                _serverCertificateValidationProvider?.Clone() as IServerCertificateValidationProvider);

            return(await metadataExchangeResolver.DownloadMetadataFileAsync(cancellationToken).ConfigureAwait(false));
        }
        private async Task LoadAsEPRAsync(XmlNS.XmlReader reader, CancellationToken cancellationToken)
        {
            using (var dictionaryReader = XmlNS.XmlDictionaryReader.CreateDictionaryReader(reader))
            {
                EndpointAddress epr = await AsyncHelper.RunAsync(() => EndpointAddress.ReadFrom(dictionaryReader), cancellationToken).ConfigureAwait(false);

                MetadataExchangeResolver      resolver         = MetadataExchangeResolver.Create(epr, null, null, null);
                IEnumerable <MetadataSection> resolvedMetadata = await resolver.ResolveMetadataAsync(cancellationToken).ConfigureAwait(false);

                _metadataSections.AddRange(resolvedMetadata);
            }
        }
Beispiel #3
0
        private static MetadataExchangeResolver CreateMetadataExchangeClient(EndpointAddress endpointAddress)
        {
            MetadataExchangeResolver metadataExchangeClient = null;

            string scheme = endpointAddress.Uri.Scheme;

            if (String.Compare(scheme, MetadataConstants.Uri.UriSchemeHttp, StringComparison.OrdinalIgnoreCase) == 0)
            {
                WSHttpBinding binding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpBinding();
                binding.MaxReceivedMessageSize             = MaxRecievedMexMessageSize;
                binding.ReaderQuotas.MaxNameTableCharCount = MaxNameTableCharCount;
                binding.ReaderQuotas.MaxDepth        = MaxDepth;
                binding.ReaderQuotas.MaxBytesPerRead = MaxBytesPerRead;
                metadataExchangeClient = new MetadataExchangeResolver(binding);
            }
            else if (String.Compare(scheme, MetadataConstants.Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) == 0)
            {
                WSHttpBinding binding = (WSHttpBinding)MetadataExchangeBindings.CreateMexHttpsBinding();
                binding.MaxReceivedMessageSize             = MaxRecievedMexMessageSize;
                binding.ReaderQuotas.MaxNameTableCharCount = MaxNameTableCharCount;
                binding.ReaderQuotas.MaxDepth        = MaxDepth;
                binding.ReaderQuotas.MaxBytesPerRead = MaxBytesPerRead;
                metadataExchangeClient = new MetadataExchangeResolver(binding);
            }
            else if (String.Compare(scheme, MetadataConstants.Uri.UriSchemeNetTcp, StringComparison.OrdinalIgnoreCase) == 0)
            {
                CustomBinding binding = (CustomBinding)MetadataExchangeBindings.CreateMexTcpBinding();
                binding.Elements.Find <TcpTransportBindingElement>().MaxReceivedMessageSize = MaxRecievedMexMessageSize;
                metadataExchangeClient = new MetadataExchangeResolver(binding);
            }
            else if (String.Compare(scheme, MetadataConstants.Uri.UriSchemeNetPipe, StringComparison.OrdinalIgnoreCase) == 0)
            {
                CustomBinding binding = (CustomBinding)MetadataExchangeBindings.CreateMexNamedPipeBinding();
                binding.Elements.Find <NamedPipeTransportBindingElement>().MaxReceivedMessageSize = MaxRecievedMexMessageSize;
                metadataExchangeClient = new MetadataExchangeResolver(binding);
            }
            else
            {
                throw new MetadataExchangeException(MetadataResources.ErrCannotCreateAMetadataExchangeClientFormat, endpointAddress.Uri.OriginalString, scheme);
            }

            return(metadataExchangeClient);
        }
        private async Task LoadAsync(string uri, string baseUrl, string basePath, CancellationToken cancellationToken)
        {
            if (CanLoad(uri, baseUrl, basePath, out Uri serviceUri))
            {
                if (serviceUri.Scheme == MetadataConstants.Uri.UriSchemeFile)
                {
                    var fileInfoList = MetadataFileNameManager.ResolveFiles(serviceUri.LocalPath);
                    foreach (var fileInfo in fileInfoList)
                    {
                        if (!IsUriProcessed(fileInfo.FullName))
                        {
                            using (var fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
                            {
                                await LoadFromStreamAsync(fileStream, fileInfo.FullName, fileInfo.DirectoryName, cancellationToken).ConfigureAwait(false);
                            }
                        }
                    }
                }
                else
                {
                    if (!IsUriProcessed(serviceUri.AbsoluteUri))
                    {
                        // Clone providers as they may be in use for a different URI.
                        MetadataExchangeResolver metadataExchangeResolver = MetadataExchangeResolver.Create(
                            new EndpointAddress(serviceUri),
                            _httpCredentialsProvider?.Clone() as IHttpCredentialsProvider,
                            _clientCertificatesProvider?.Clone() as IClientCertificateProvider,
                            _serverCertificateValidationProvider?.Clone() as IServerCertificateValidationProvider);

                        var metadataSections = await metadataExchangeResolver.ResolveMetadataAsync(cancellationToken).ConfigureAwait(false);

                        _metadataSections.AddRange(metadataSections);
                    }
                }
            }
            else
            {
                throw new MetadataExchangeException(MetadataResources.ErrInvalidUriFormat, uri);
            }
        }
Beispiel #5
0
        public static MetadataExchangeResolver Create(
            EndpointAddress endpointAddress,
            IHttpCredentialsProvider userCredentialsProvider,
            IClientCertificateProvider clientCertificatesProvider,
            IServerCertificateValidationProvider serverCertificateValidationProvider)
        {
            if (endpointAddress == null)
            {
                throw new ArgumentNullException(nameof(endpointAddress));
            }

            MetadataExchangeResolver resolver = CreateMetadataExchangeClient(endpointAddress);

            resolver.EndpointAddress                     = endpointAddress;
            resolver.HttpCredentialsProvider             = userCredentialsProvider;
            resolver.ClientCertificatesProvider          = clientCertificatesProvider;
            resolver.ServerCertificateValidationProvider = serverCertificateValidationProvider;
            resolver.OperationTimeout                    = TimeSpan.MaxValue;
            resolver.ResolveMetadataReferences           = true;
            resolver.MaximumResolvedReferences           = MaximumResolvedReferencesDefault;
            resolver.HttpCredentials                     = System.Net.CredentialCache.DefaultCredentials;

            return(resolver);
        }