internal void ReadFrom(DiscoveryVersion discoveryVersion, XmlReader reader) { if (discoveryVersion == null) { throw FxTrace.Exception.ArgumentNull("discoveryVersion"); } if (reader == null) { throw FxTrace.Exception.ArgumentNull("reader"); } reader.MoveToContent(); if (reader.IsEmptyElement) { reader.Read(); return; } int startDepth = reader.Depth; reader.ReadStartElement(); this.endpointAddress = SerializationUtility.ReadEndpointAddress(discoveryVersion, reader); this.extensions = null; this.duration = TimeSpan.MaxValue; while (true) { reader.MoveToContent(); if ((reader.NodeType == XmlNodeType.EndElement) && (reader.Depth == startDepth)) { break; } else if (reader.IsStartElement(ProtocolStrings.SchemaNames.DurationElement, ProtocolStrings.VersionInternal.Namespace)) { this.duration = SerializationUtility.ReadDuration(reader); } else if (reader.IsStartElement()) { XElement xElement = XElement.ReadFrom(reader) as XElement; Extensions.Add(xElement); } else { reader.Read(); } } }
public static Uri ReadScopes(Collection <Uri> scopes, XmlReader reader) { Uri scopeMatchBy = null; if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if ((reader.NamespaceURI.Length == 0) && (reader.Name.Equals(ProtocolStrings.SchemaNames.MatchByAttribute))) { string scopeMatchByStr = reader.Value; try { scopeMatchBy = new Uri(scopeMatchByStr, UriKind.RelativeOrAbsolute); } catch (FormatException fe) { throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlUriFormatError(scopeMatchByStr), fe)); } break; } } reader.MoveToElement(); } if (reader.IsEmptyElement) { reader.Read(); } else { reader.ReadStartElement(); string listOfUrisAsString = reader.ReadString(); if (!string.IsNullOrEmpty(listOfUrisAsString)) { SerializationUtility.ParseUriList(listOfUrisAsString, scopes, UriKind.Absolute); } reader.ReadEndElement(); } return(scopeMatchBy); }
public static void ReadListenUris(Collection <Uri> listenUris, XmlReader reader) { if (reader.IsEmptyElement) { reader.Read(); } else { reader.ReadStartElement(); string listOfUrisAsString = reader.ReadString(); if (!string.IsNullOrEmpty(listOfUrisAsString)) { SerializationUtility.ParseUriList(listOfUrisAsString, listenUris, UriKind.RelativeOrAbsolute); } reader.ReadEndElement(); } }
public static void ReadContractTypeNames(Collection <XmlQualifiedName> contractTypeNames, XmlReader reader) { if (reader.IsEmptyElement) { reader.Read(); } else { reader.ReadStartElement(); string listOfQNamesAsStr = reader.ReadString(); if (!string.IsNullOrEmpty(listOfQNamesAsStr)) { SerializationUtility.ParseQNameList(listOfQNamesAsStr, contractTypeNames, reader); } reader.ReadEndElement(); } }
public static TimeSpan ReadDuration(XmlReader reader) { TimeSpan timeout = TimeSpan.MaxValue; if (reader.IsEmptyElement) { reader.Read(); } else { reader.ReadStartElement(); string timeoutString = reader.ReadString(); timeout = SerializationUtility.ReadTimespan(timeoutString, SR2.DiscoveryXmlDurationDeserializationError(timeoutString)); if (timeout <= TimeSpan.Zero) { throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlDurationLessThanZero(timeout)));; } reader.ReadEndElement(); } return(timeout); }
internal void WriteTo(DiscoveryVersion discoveryVersion, XmlWriter writer) { if (discoveryVersion == null) { throw FxTrace.Exception.ArgumentNull("discoveryVersion"); } if (writer == null) { throw FxTrace.Exception.ArgumentNull("writer"); } SerializationUtility.WriteContractTypeNames(discoveryVersion, this.contractTypeNames, writer); SerializationUtility.WriteScopes(discoveryVersion, this.scopes, this.scopeMatchBy, writer); if (this.maxResults != int.MaxValue) { writer.WriteElementString( ProtocolStrings.SchemaNames.MaxResultsElement, ProtocolStrings.VersionInternal.Namespace, this.maxResults.ToString(CultureInfo.InvariantCulture)); } if (this.duration != TimeSpan.MaxValue) { writer.WriteElementString( ProtocolStrings.SchemaNames.DurationElement, ProtocolStrings.VersionInternal.Namespace, XmlConvert.ToString(this.Duration)); } if (this.extensions != null) { foreach (XElement xElement in Extensions) { xElement.WriteTo(writer); } } }
internal void ReadFrom(DiscoveryVersion discoveryVersion, XmlReader reader) { if (discoveryVersion == null) { throw FxTrace.Exception.ArgumentNull("discoveryVersion"); } if (reader == null) { throw FxTrace.Exception.ArgumentNull("reader"); } this.contractTypeNames = null; this.scopes = null; this.scopeMatchBy = DiscoveryDefaults.ScopeMatchBy; this.extensions = null; this.duration = TimeSpan.MaxValue; this.maxResults = int.MaxValue; reader.MoveToContent(); if (reader.IsEmptyElement) { reader.Read(); return; } int startDepth = reader.Depth; reader.ReadStartElement(); if (reader.IsStartElement(ProtocolStrings.SchemaNames.TypesElement, discoveryVersion.Namespace)) { this.contractTypeNames = new ContractTypeNameCollection(); SerializationUtility.ReadContractTypeNames(this.contractTypeNames, reader); } if (reader.IsStartElement(ProtocolStrings.SchemaNames.ScopesElement, discoveryVersion.Namespace)) { this.scopes = new ScopeCollection(); Uri scopeMatchBy = SerializationUtility.ReadScopes(this.scopes, reader); if (scopeMatchBy != null) { this.scopeMatchBy = discoveryVersion.Implementation.ToVersionIndependentScopeMatchBy(scopeMatchBy); } } while (true) { reader.MoveToContent(); if ((reader.NodeType == XmlNodeType.EndElement) && (reader.Depth == startDepth)) { break; } else if (reader.IsStartElement(ProtocolStrings.SchemaNames.MaxResultsElement, ProtocolStrings.VersionInternal.Namespace)) { this.maxResults = SerializationUtility.ReadMaxResults(reader); } else if (reader.IsStartElement(ProtocolStrings.SchemaNames.DurationElement, ProtocolStrings.VersionInternal.Namespace)) { this.duration = SerializationUtility.ReadDuration(reader); } else if (reader.IsStartElement()) { XElement xElement = XElement.ReadFrom(reader) as XElement; Extensions.Add(xElement); } else { reader.Read(); } } reader.ReadEndElement(); }
internal void ReadFrom(DiscoveryVersion discoveryVersion, XmlReader reader) { ThrowIfOpen(); if (discoveryVersion == null) { throw FxTrace.Exception.ArgumentNull("discoveryVersion"); } if (reader == null) { throw FxTrace.Exception.ArgumentNull("reader"); } this.endpointAddress = new EndpointAddress(EndpointAddress.AnonymousUri); this.contractTypeNames = null; this.scopes = null; this.listenUris = null; this.metadataVersion = 0; this.extensions = null; this.isOpen = false; reader.MoveToContent(); if (reader.IsEmptyElement) { throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlEndpointNull)); } int startDepth = reader.Depth; reader.ReadStartElement(); this.endpointAddress = SerializationUtility.ReadEndpointAddress(discoveryVersion, reader); if (reader.IsStartElement(ProtocolStrings.SchemaNames.TypesElement, discoveryVersion.Namespace)) { this.contractTypeNames = new OpenableContractTypeNameCollection(false); SerializationUtility.ReadContractTypeNames(this.contractTypeNames, reader); } if (reader.IsStartElement(ProtocolStrings.SchemaNames.ScopesElement, discoveryVersion.Namespace)) { this.scopes = new OpenableScopeCollection(false); SerializationUtility.ReadScopes(this.scopes, reader); } if (reader.IsStartElement(ProtocolStrings.SchemaNames.XAddrsElement, discoveryVersion.Namespace)) { this.listenUris = new OpenableCollection <Uri>(false); SerializationUtility.ReadListenUris(listenUris, reader); } if (reader.IsStartElement(ProtocolStrings.SchemaNames.MetadataVersionElement, discoveryVersion.Namespace)) { this.metadataVersion = SerializationUtility.ReadMetadataVersion(reader); } while (true) { reader.MoveToContent(); if ((reader.NodeType == XmlNodeType.EndElement) && (reader.Depth == startDepth)) { break; } else if (reader.IsStartElement()) { this.Extensions.Add(XElement.ReadFrom(reader) as XElement); } else { reader.Read(); } } reader.ReadEndElement(); }