private static MetadataFileType DetermineFileType(XmlNS.XmlReader reader) { try { if (reader.IsStartElement(MetadataConstants.WSDL.Elements.Root, MetadataConstants.WSDL.NamespaceUri)) { return(MetadataFileType.Wsdl); } else if (reader.IsStartElement(MetadataConstants.XmlSchema.Elements.Root, MetadataConstants.XmlSchema.NamespaceUri)) { return(MetadataFileType.Xsd); } else if (reader.IsStartElement(MetadataConstants.WSPolicy.Elements.Policy, MetadataConstants.WSPolicy.NamespaceUri) || reader.IsStartElement(MetadataConstants.WSPolicy.Elements.Policy, MetadataConstants.WSPolicy.NamespaceUri15)) { return(MetadataFileType.Policy); } else if (reader.IsStartElement(MetadataConstants.WSAddressing.Elements.EndpointReference, MetadataConstants.WSAddressing.NamespaceUri)) { return(MetadataFileType.Epr); } else { return(MetadataFileType.UnknownXml); } } catch (XmlNS.XmlException) { //This must mean that the document isn't an XML Document so we continue trying other things... return(MetadataFileType.NonXml); } }
private async Task LoadAsWsdlAsync(XmlNS.XmlReader reader, string uri, string basePath, CancellationToken cancellationToken) { WsdlNS.ServiceDescription wsdl = await AsyncHelper.RunAsync(() => WsdlNS.ServiceDescription.Read(reader), cancellationToken).ConfigureAwait(false); wsdl.RetrievalUrl = uri; if (_resolveExternalDocs) { foreach (WsdlNS.Import import in wsdl.Imports) { if (!string.IsNullOrWhiteSpace(import.Location)) { var resolvedLocation = await LoadAsSchemaImportLocationAsync(import.Location, uri, basePath, import.Namespace, ".wsdl", cancellationToken).ConfigureAwait(false); import.Location = resolvedLocation; } } foreach (XmlNS.Schema.XmlSchema schema in wsdl.Types.Schemas) { schema.SourceUri = uri; await LoadAsXmlSchemaIncludesAsync(schema, wsdl.RetrievalUrl, basePath, cancellationToken).ConfigureAwait(false); } } _metadataSections.Add(MetadataSection.CreateFromServiceDescription(wsdl)); }
private void LoadAsUnknownXml(XmlNS.XmlReader reader) { var doc = new XmlNS.XmlDocument(); doc.XmlResolver = null; doc.Load(reader); XmlNS.XmlElement unknownXml = doc.DocumentElement; _metadataSections.Add(new MetadataSection(null, null, unknownXml)); }
private void LoadAsPolicy(XmlNS.XmlReader reader) { var doc = new XmlNS.XmlDocument(); doc.XmlResolver = null; doc.Load(reader); XmlNS.XmlElement policy = doc.DocumentElement; _metadataSections.Add(MetadataSection.CreateFromPolicy(policy, null)); }
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); } }
private async Task LoadAsXmlSchemaAsync(XmlNS.XmlReader reader, string uri, string basePath, CancellationToken cancellationToken) { var schema = await AsyncHelper.RunAsync(() => XmlNS.Schema.XmlSchema.Read(reader, null), cancellationToken).ConfigureAwait(false); _metadataSections.Add(MetadataSection.CreateFromSchema(schema)); schema.SourceUri = uri; if (_resolveExternalDocs) { await LoadAsXmlSchemaIncludesAsync(schema, uri, basePath, cancellationToken).ConfigureAwait(false); } }
public override System.Boolean CanDeserialize(Microsoft.Xml.XmlReader xmlReader) { return(true); }