internal static void ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext) { XmlElement assertion = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), TransportPolicyConstants.WindowsTransportSecurityName, TransportPolicyConstants.DotNetFramingNamespace, true); if (assertion != null) { WindowsStreamSecurityBindingElement windowsBindingElement = new WindowsStreamSecurityBindingElement(); XmlReader reader = new XmlNodeReader(assertion); reader.ReadStartElement(); string protectionLevelString = null; if (reader.IsStartElement( TransportPolicyConstants.ProtectionLevelName, TransportPolicyConstants.DotNetFramingNamespace) && !reader.IsEmptyElement) { protectionLevelString = reader.ReadElementContentAsString(); } if (string.IsNullOrEmpty(protectionLevelString)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException( SR.GetString(SR.ExpectedElementMissing, TransportPolicyConstants.ProtectionLevelName, TransportPolicyConstants.DotNetFramingNamespace))); } windowsBindingElement.ProtectionLevel = (ProtectionLevel)Enum.Parse(typeof(ProtectionLevel), protectionLevelString); policyContext.BindingElements.Add(windowsBindingElement); } }
private void GetAppliesToQName(XmlElement rootElement, out string localName, out string namespaceUri) { localName = namespaceUri = null; XmlElement appliesToElement = GetAppliesToElement(rootElement); if (appliesToElement != null) { using (XmlReader reader = new XmlNodeReader(appliesToElement)) { reader.ReadStartElement(); reader.MoveToContent(); localName = reader.LocalName; namespaceUri = reader.NamespaceURI; } } }
internal static void ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext) { XmlElement node = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), "SslTransportSecurity", "http://schemas.microsoft.com/ws/2006/05/framing/policy", true); if (node != null) { SslStreamSecurityBindingElement item = new SslStreamSecurityBindingElement(); XmlReader reader = new XmlNodeReader(node); reader.ReadStartElement(); item.RequireClientCertificate = reader.IsStartElement("RequireClientCertificate", "http://schemas.microsoft.com/ws/2006/05/framing/policy"); if (item.RequireClientCertificate) { reader.ReadElementString(); } policyContext.BindingElements.Add(item); } }
public static void Main() { XmlNodeReader reader = null; try { //Create and load an XML document. XmlDocument doc = new XmlDocument(); doc.LoadXml("<!DOCTYPE book [<!ENTITY h 'hardcover'>]>" + "<book>" + "<title>Pride And Prejudice</title>" + "<misc>&h;</misc>" + "</book>"); //Create the reader. reader = new XmlNodeReader(doc); reader.MoveToContent(); //Move to the root element. reader.Read(); //Move to title start tag. reader.Skip(); //Skip the title element. //Read the misc start tag. The reader is now positioned on //the entity reference node. reader.ReadStartElement(); //You must call ResolveEntity to expand the entity reference. //The entity replacement text is then parsed and returned as a child node. Console.WriteLine("Expand the entity..."); reader.ResolveEntity(); Console.WriteLine("The entity replacement text is returned as a text node."); reader.Read(); Console.WriteLine("NodeType: {0} Value: {1}", reader.NodeType, reader.Value); Console.WriteLine("An EndEntity node closes the entity reference scope."); reader.Read(); Console.WriteLine("NodeType: {0} Name: {1}", reader.NodeType, reader.Name); } finally { if (reader != null) { reader.Close(); } } }
private T GetAppliesTo <T>(XmlElement rootXml, XmlObjectSerializer serializer) { XmlElement appliesToElement = GetAppliesToElement(rootXml); if (appliesToElement != null) { using (XmlReader reader = new XmlNodeReader(appliesToElement)) { reader.ReadStartElement(); lock (serializer) { return((T)serializer.ReadObject(reader)); } } } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SRServiceModel.NoAppliesToPresent)); } }
internal static void ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext) { XmlElement assertion = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), TransportPolicyConstants.SslTransportSecurityName, TransportPolicyConstants.DotNetFramingNamespace, true); if (assertion != null) { SslStreamSecurityBindingElement sslBindingElement = new SslStreamSecurityBindingElement(); XmlReader reader = new XmlNodeReader(assertion); reader.ReadStartElement(); sslBindingElement.RequireClientCertificate = reader.IsStartElement( TransportPolicyConstants.RequireClientCertificateName, TransportPolicyConstants.DotNetFramingNamespace); if (sslBindingElement.RequireClientCertificate) { reader.ReadElementString(); } policyContext.BindingElements.Add(sslBindingElement); } }
internal static void ImportPolicy(MetadataImporter importer, PolicyConversionContext policyContext) { XmlElement node = PolicyConversionContext.FindAssertion(policyContext.GetBindingAssertions(), "WindowsTransportSecurity", "http://schemas.microsoft.com/ws/2006/05/framing/policy", true); if (node != null) { WindowsStreamSecurityBindingElement item = new WindowsStreamSecurityBindingElement(); XmlReader reader = new XmlNodeReader(node); reader.ReadStartElement(); string str = null; if (reader.IsStartElement("ProtectionLevel", "http://schemas.microsoft.com/ws/2006/05/framing/policy") && !reader.IsEmptyElement) { str = reader.ReadElementContentAsString(); } if (string.IsNullOrEmpty(str)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("ExpectedElementMissing", new object[] { "ProtectionLevel", "http://schemas.microsoft.com/ws/2006/05/framing/policy" }))); } item.ProtectionLevel = (System.Net.Security.ProtectionLevel)Enum.Parse(typeof(System.Net.Security.ProtectionLevel), str); policyContext.BindingElements.Add(item); } }