Пример #1
0
        /// <summary>
        /// </summary>
        /// <param name="uri">The service Uri to load service metadata from.</param>
        /// <param name="httpCredentialsProvider"></param>
        /// <param name="clientCertificatesProvider"></param>
        /// <param name="serverCertificateValidationProvider"></param>
        public MetadataDocumentLoader(string uri, IHttpCredentialsProvider httpCredentialsProvider, IClientCertificateProvider clientCertificatesProvider, IServerCertificateValidationProvider serverCertificateValidationProvider)
        {
            _httpCredentialsProvider             = httpCredentialsProvider;
            _clientCertificatesProvider          = clientCertificatesProvider;
            _serverCertificateValidationProvider = serverCertificateValidationProvider;

            if (string.IsNullOrEmpty(uri))
            {
                throw new ArgumentNullException(nameof(uri));
            }

            if (!CanLoad(uri, string.Empty, Directory.GetCurrentDirectory(), out Uri metadataUri))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, MetadataResources.ErrInvalidUriFormat, uri));
            }

            if (metadataUri.IsFile)
            {
                // the input could be a reference to a list of files specified with wildcards, let's check.
                var fileInfoList = MetadataFileNameManager.ResolveFiles(metadataUri.LocalPath);

                // when only the wsdl file is specified, we need to resolve any schema references.
                _resolveExternalDocs = fileInfoList.Length == 1;
                this.metadataSourceFiles.AddRange(fileInfoList.Select(fi => new Uri(fi.FullName, UriKind.Absolute)));
            }
            else
            {
                _resolveExternalDocs   = true;
                this.MetadataSourceUrl = metadataUri;
            }
        }
Пример #2
0
        /// <summary>
        /// </summary>
        /// <param name="metadataFiles">A collection containing the location of wsdl/schema documents to load service metadata from.</param>
        /// <param name="resolveExternalDocuments">if true, WSDL imports and XmlSchema Includes will be attempted to be resolved.</param>
        /// <param name="httpCredentialsProvider"></param>
        /// <param name="clientCertificatesProvider"></param>
        /// <param name="serverCertificateValidationProvider"></param>
        public MetadataDocumentLoader(IEnumerable <string> metadataFiles, bool resolveExternalDocuments, IHttpCredentialsProvider httpCredentialsProvider, IClientCertificateProvider clientCertificatesProvider, IServerCertificateValidationProvider serverCertificateValidationProvider)
        {
            _httpCredentialsProvider             = httpCredentialsProvider;
            _clientCertificatesProvider          = clientCertificatesProvider;
            _serverCertificateValidationProvider = serverCertificateValidationProvider;

            if (metadataFiles == null)
            {
                throw new ArgumentNullException(nameof(metadataFiles));
            }

            foreach (var uri in metadataFiles)
            {
                if (!CanLoad(uri, string.Empty, Directory.GetCurrentDirectory(), out Uri metadataUri))
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, MetadataResources.ErrInvalidUriFormat, uri));
                }

                if (!metadataUri.IsFile)
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, MetadataResources.ErrUrlNotAllowedOnMultipleInputsFormat, metadataUri));
                }

                var fileInfoList = MetadataFileNameManager.ResolveFiles(metadataUri.LocalPath);
                this.metadataSourceFiles.AddRange(fileInfoList.Select(fi => new Uri(fi.FullName, UriKind.Absolute)));
            }

            _resolveExternalDocs = resolveExternalDocuments;
        }
Пример #3
0
        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);
            }
        }