protected override bool TryReadRoleDescriptor(XmlDictionaryReader reader, out RoleDescriptor role)
        {
            if (!reader.IsStartElement(Saml2MetadataConstants.Elements.RoleDescriptor, Saml2MetadataConstants.Namespace))
            {
                return(Out.False(out role));
            }

            var d = null as RoleDescriptor;

            if (reader.TryReadFederationEndpointType(out var type))
            {
                if (type == FederationEndpointType.ApplicationService)
                {
                    d = new ApplicationServiceDescriptor();
                }
                if (type == FederationEndpointType.AttributeService)
                {
                    d = new AttributeServiceDescriptor();
                }
                if (type == FederationEndpointType.PseudonymService)
                {
                    d = new PseudonymServiceDescriptor();
                }
                if (type == FederationEndpointType.SecurityTokenService)
                {
                    d = new SecurityTokenServiceDescriptor();
                }
            }
            if (d == null)
            {
                d = new RoleDescriptor();
            }
            ReadRoleDescriptorAttributes(reader, d);

            reader.ForEachChild(r => TryReadRoleDescriptorChild(r, d), out var signature);
            d.Signature = signature;

            role = d;
            return(true);
        }
        protected virtual void WriteSecurityTokenServiceDescriptorChildren(XmlDictionaryWriter writer, SecurityTokenServiceDescriptor securityTokenServiceDescriptor)
        {
            if (securityTokenServiceDescriptor == null)
            {
                return;
            }
            if (!securityTokenServiceDescriptor.SecurityTokenServiceEndpoint.Any())
            {
                throw XmlWriterExceptionHelper.CreateRequiredChildElementMissingException(Saml2MetadataConstants.Elements.RoleDescriptor, securityTokenServiceDescriptor.GetXmlTypeName());
            }

            WriteWebServiceDescriptorChildren(writer, securityTokenServiceDescriptor);

            foreach (var securityTokenServiceEndpoint in securityTokenServiceDescriptor.SecurityTokenServiceEndpoint)
            {
                WsAddressingSerializer.WriteEndpointReferenceCollection(writer, Prefix, Elements.SecurityTokenServiceEndpoint, Namespace, securityTokenServiceEndpoint);
            }

            foreach (var singleSignOutSubscriptionEndpoint in securityTokenServiceDescriptor.SingleSignOutSubscriptionEndpoint)
            {
                WsAddressingSerializer.WriteEndpointReferenceCollection(writer, Prefix, Elements.SingleSignOutSubscriptionEndpoint, Namespace, singleSignOutSubscriptionEndpoint);
            }

            foreach (var singleSignOutNotificationEndpoint in securityTokenServiceDescriptor.SingleSignOutNotificationEndpoint)
            {
                WsAddressingSerializer.WriteEndpointReferenceCollection(writer, Prefix, Elements.SingleSignOutNotificationEndpoint, Namespace, singleSignOutNotificationEndpoint);
            }

            foreach (var passiveRequestorEndpoint in securityTokenServiceDescriptor.PassiveRequestorEndpoint)
            {
                WsAddressingSerializer.WriteEndpointReferenceCollection(writer, Prefix, Elements.PassiveRequestorEndpoint, Namespace, passiveRequestorEndpoint);
            }
        }
 protected virtual void WriteSecurityTokenServiceDescriptorAttributes(XmlDictionaryWriter writer, SecurityTokenServiceDescriptor securityTokenServiceDescriptor)
 {
     WriteWebServiceDescriptorAttributes(writer, securityTokenServiceDescriptor);
 }
 protected virtual void ReadSecurityTokenServiceDescriptorAttributes(XmlDictionaryReader reader, SecurityTokenServiceDescriptor securityTokenServiceDescriptor)
 {
     // No default attributes
 }
        protected virtual bool TryReadSecurityTokenServiceDescriptorChild(XmlDictionaryReader reader, SecurityTokenServiceDescriptor securityTokenServiceDescriptor)
        {
            if (WsAddressingSerializer.TryReadEndpointReferenceCollection(reader, Elements.SecurityTokenServiceEndpoint, Namespace, out var securityTokenServiceEndpoint))
            {
                securityTokenServiceDescriptor.SecurityTokenServiceEndpoint.Add(securityTokenServiceEndpoint);
            }
            else if (WsAddressingSerializer.TryReadEndpointReferenceCollection(reader, Elements.SingleSignOutSubscriptionEndpoint, Namespace, out var singleSignOutSubscriptionEndpoint))
            {
                securityTokenServiceDescriptor.SingleSignOutSubscriptionEndpoint.Add(singleSignOutSubscriptionEndpoint);
            }
            else if (WsAddressingSerializer.TryReadEndpointReferenceCollection(reader, Elements.SingleSignOutNotificationEndpoint, Namespace, out var singleSignOutNotificationEndpoint))
            {
                securityTokenServiceDescriptor.SingleSignOutNotificationEndpoint.Add(singleSignOutNotificationEndpoint);
            }
            else if (WsAddressingSerializer.TryReadEndpointReferenceCollection(reader, Elements.PassiveRequestorEndpoint, Namespace, out var passiveRequestorNotificationEndpoint))
            {
                securityTokenServiceDescriptor.PassiveRequestorEndpoint.Add(passiveRequestorNotificationEndpoint);
            }
            else
            {
                return(TryReadWebServiceDescriptorChild(reader, securityTokenServiceDescriptor));
            }

            return(true);
        }