/// <summary>
        /// Serializes a TokenRestrictionTemplate to a string containing an xml representation of
        /// the token restriction template.
        /// </summary>
        /// <param name="template">TokenRestrictionTemplate instance to serialize to a string</param>
        /// <returns>An xml string representation of the TokenRestrictionTemplate instance</returns>
        public static string Serialize(TokenRestrictionTemplate template)
        {
            if (template.PrimaryVerificationKey == null &&
                template.OpenIdConnectDiscoveryDocument == null)
            {
                throw new InvalidDataContractException(StringTable.PrimaryVerificationKeyAndOpenIdConnectDiscoveryDocumentAreNull);
            }

            if (template.OpenIdConnectDiscoveryDocument != null &&
                String.IsNullOrEmpty(template.OpenIdConnectDiscoveryDocument.OpenIdDiscoveryUri))
            {
                throw new InvalidDataContractException(String.Format(CultureInfo.InvariantCulture, StringTable.ArgumentStringIsNullOrEmpty, "OpenIdDiscoveryUri"));
            }

            Uri openIdDiscoveryUri;

            if (template.OpenIdConnectDiscoveryDocument != null && !Uri.TryCreate(template.OpenIdConnectDiscoveryDocument.OpenIdDiscoveryUri, UriKind.Absolute, out openIdDiscoveryUri))
            {
                throw new InvalidDataContractException(String.Format(CultureInfo.InvariantCulture, StringTable.StringIsNotAbsoluteUri, "OpenIdConnectDiscoveryDocument.OpenIdDiscoveryUri"));
            }



            DataContractSerializer serializer = GetSerializer();

            if (template.TokenType == TokenType.SWT)
            {
                if (!Uri.IsWellFormedUriString(template.Issuer, UriKind.Absolute))
                {
                    throw new InvalidDataContractException(String.Format(CultureInfo.InvariantCulture, StringTable.InvalidAbsoluteUriInSWTToken, "template.Issuer"));
                }
                if (!Uri.IsWellFormedUriString(template.Audience, UriKind.Absolute))
                {
                    throw new InvalidDataContractException(String.Format(CultureInfo.InvariantCulture, StringTable.InvalidAbsoluteUriInSWTToken, "template.Audience"));
                }
            }

            return(MediaServicesLicenseTemplateSerializer.SerializeToXml(template, serializer));
        }
        /// <summary>
        /// Serializes a TokenRestrictionTemplate to a string containing an xml representation of
        /// the token restriction template.
        /// </summary>
        /// <param name="template">TokenRestrictionTemplate instance to serialize to a string</param>
        /// <returns>An xml string representation of the TokenRestrictionTemplate instance</returns>
        public static string Serialize(TokenRestrictionTemplate template)
        {
            DataContractSerializer serializer = GetSerializer();

            return(MediaServicesLicenseTemplateSerializer.SerializeToXml(template, serializer));
        }