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 WriteApplicationServiceDescriptorChildren(XmlDictionaryWriter writer, ApplicationServiceDescriptor applicationServiceDescriptor)
        {
            if (applicationServiceDescriptor == null)
            {
                return;
            }
            if (!applicationServiceDescriptor.ApplicationServiceEndpoint.Any())
            {
                throw XmlWriterExceptionHelper.CreateRequiredChildElementMissingException(Saml2MetadataConstants.Elements.RoleDescriptor, applicationServiceDescriptor.GetXmlTypeName());
            }

            WriteWebServiceDescriptorChildren(writer, applicationServiceDescriptor);

            foreach (var applicationServiceEndpoint in applicationServiceDescriptor.ApplicationServiceEndpoint)
            {
                WsAddressingSerializer.WriteEndpointReferenceCollection(writer, Prefix, Elements.ApplicationServiceEndpoint, Namespace, applicationServiceEndpoint);
            }

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

            foreach (var passiveRequestorEndpoint in applicationServiceDescriptor.PassiveRequestorEndpoint)
            {
                WsAddressingSerializer.WriteEndpointReferenceCollection(writer, Prefix, Elements.PassiveRequestorEndpoint, Namespace, passiveRequestorEndpoint);
            }
        }
 protected virtual void WriteApplicationServiceDescriptorAttributes(XmlDictionaryWriter writer, ApplicationServiceDescriptor applicationServiceDescriptor)
 {
     WriteWebServiceDescriptorAttributes(writer, applicationServiceDescriptor);
 }
 protected virtual void ReadApplicationServiceDescriptorAttributes(XmlDictionaryReader reader, ApplicationServiceDescriptor applicationServiceDescriptor)
 {
     // No default attributes
 }
        protected virtual bool TryReadApplicationServiceDescriptorChild(XmlDictionaryReader reader, ApplicationServiceDescriptor applicationServiceDescriptor)
        {
            if (WsAddressingSerializer.TryReadEndpointReferenceCollection(reader, Elements.SingleSignOutNotificationEndpoint, Namespace, out var singleSignOutNotificationEndpoint))
            {
                applicationServiceDescriptor.SingleSignOutNotificationEndpoint.Add(singleSignOutNotificationEndpoint);
            }
            else if (WsAddressingSerializer.TryReadEndpointReferenceCollection(reader, Elements.ApplicationServiceEndpoint, Namespace, out var applicationServiceEndpoint))
            {
                applicationServiceDescriptor.ApplicationServiceEndpoint.Add(applicationServiceEndpoint);
            }
            else if (WsAddressingSerializer.TryReadEndpointReferenceCollection(reader, Elements.PassiveRequestorEndpoint, Namespace, out var passiveRequestorNotificationEndpoint))
            {
                applicationServiceDescriptor.PassiveRequestorEndpoint.Add(passiveRequestorNotificationEndpoint);
            }
            else
            {
                return(TryReadWebServiceDescriptorChild(reader, applicationServiceDescriptor));
            }

            return(true);
        }