WriteString() public method

public WriteString ( System value ) : void
value System
return void
Example #1
0
        private void WriteHeader(XmlDictionaryWriter writer)
        {
            var nonce = new byte[64];
            RandomNumberGenerator.Create().GetBytes(nonce);
            string created = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.mszzzz");

            writer.WriteStartElement("wsse", "UsernameToken", null);
            writer.WriteAttributeString("wsu:Id", "UsernameToken-1");
            writer.WriteStartElement("wsse", "Username", null);
            writer.WriteString(SystemUser);
            writer.WriteEndElement();//End Username 
            writer.WriteStartElement("wsse", "Password", null);
            writer.WriteAttributeString("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
            writer.WriteString(ComputePasswordDigest(SystemPassword, nonce, created));
            writer.WriteEndElement();//End Password 
            writer.WriteStartElement("wsse", "Nonce", null);
            writer.WriteAttributeString("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
            writer.WriteBase64(nonce, 0, nonce.Length);
            writer.WriteEndElement();//End Nonce 
            writer.WriteStartElement("wsu", "Created", null);
            writer.WriteString(created);
            writer.WriteEndElement();//End Created
            writer.WriteEndElement();//End UsernameToken
            writer.Flush();
        }
 protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     if (this.address != null)
     {
         writer.WriteStartElement("netdx", "Address", "http://schemas.microsoft.com/2008/04/netduplex");
         writer.WriteString(this.address);
         writer.WriteEndElement();
     }
     writer.WriteStartElement("netdx", "SessionId", "http://schemas.microsoft.com/2008/04/netduplex");
     writer.WriteString(this.sessionId);
     writer.WriteEndElement();
 }
        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
        {
            writer.WriteStartElement("ID");
            //writer.WriteString("{id}");
            writer.WriteString("1408");
            writer.WriteEndElement();

            writer.WriteStartElement("MDP");
            //writer.WriteString("{mdp}");
            writer.WriteString("fophjkl32");
            writer.WriteEndElement();
        }
 private void WriteHeader(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement("wsse", "UsernameToken", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
     writer.WriteXmlnsAttribute("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
     writer.WriteStartElement("wsse", "Username", null);
     writer.WriteString(SystemUser);
     writer.WriteEndElement();//End Username 
     writer.WriteStartElement("wsse", "Password", null);
     writer.WriteAttributeString("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
     writer.WriteString(SystemPassword);
     writer.WriteEndElement();//End Password 
     writer.WriteEndElement();//End UsernameToken
     writer.Flush();
 }
 public void WriteTo(XmlDictionaryWriter writer, string prefix, XmlDictionaryString localName, XmlDictionaryString ns, XmlDictionaryString valueTypeLocalName, XmlDictionaryString valueTypeNs)
 {
     writer.WriteStartElement(prefix, localName, ns);
     writer.WriteStartAttribute(valueTypeLocalName, valueTypeNs);
     if (valueTypeUriDictionaryString != null)
         writer.WriteString(valueTypeUriDictionaryString);
     else
         writer.WriteString(valueTypeUri);
     writer.WriteEndAttribute();
     writer.WriteStartAttribute(XD.SecurityJan2004Dictionary.EncodingType, null);
     writer.WriteString(XD.SecurityJan2004Dictionary.EncodingTypeValueBase64Binary);
     writer.WriteEndAttribute();
     writer.WriteBase64(this.negotiationData, 0, this.negotiationData.Length);
     writer.WriteEndElement();
 }
 public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     writer.WriteStartElement(this.prefix, this.elementName, dictionaryManager.XmlSignatureDictionary.Namespace);
     writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
     if (this.algorithmDictionaryString != null)
     {
         writer.WriteString(this.algorithmDictionaryString);
     }
     else
     {
         writer.WriteString(this.algorithm);
     }
     writer.WriteEndAttribute();
     writer.WriteEndElement();
 }
            public void WriteJson(XmlDictionaryWriter writer)
            {
                writer.WriteStartElement(MetadataStrings.TypeString);
                writer.WriteAttributeString("type", "string");
                writer.WriteString(String.Format("{0}{1}{2}", this.TypeName, MetadataStrings.NamespaceMarker, this.TypeNamespace));
                writer.WriteEndElement();

                writer.WriteStartElement(MetadataStrings.KeyString);
                writer.WriteAttributeString("type", "array");
                foreach (string keyitem in this.Key)
                {
                    writer.WriteStartElement("item");
                    writer.WriteAttributeString("type", "string");
                    writer.WriteValue(keyitem);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();

                writer.WriteStartElement(MetadataStrings.FieldsString);
                writer.WriteAttributeString("type", "object");
                foreach (TypePropertyMetadata field in this.Properties)
                {
                    field.WriteJson(writer);
                }
                writer.WriteEndElement();

                this.WriteValidationRulesMetadata(writer);
            }
 public override void WriteEndObject(XmlDictionaryWriter writer)
 {
     if (!skipName)
     {
         writer.WriteString("\n\t");
         writer.WriteEndElement();
     }
 }
 protected override void OnBodyToString(XmlDictionaryWriter writer)
 {
     if (this.bodyWriter.IsBuffered)
     {
         this.bodyWriter.WriteBodyContents(writer);
     }
     else
     {
         writer.WriteString(System.ServiceModel.SR.GetString("MessageBodyIsStream"));
     }
 }
            protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
            {
                writer.WriteStartElement("root");
                writer.WriteAttributeString("type", "object");

                writer.WriteStartElement("ErrorMessage");
                writer.WriteAttributeString("type", "string");
                writer.WriteString(this.validationException.ValidationResult.ErrorMessage);
                writer.WriteEndElement();

                writer.WriteStartElement("MemberNames");
                writer.WriteAttributeString("type", "array");
                foreach (var member in this.validationException.ValidationResult.MemberNames)
                {
                    writer.WriteStartElement("item");
                    writer.WriteAttributeString("type", "string");
                    writer.WriteString(member);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();

                writer.WriteEndElement();
            }
 public void WriteTo(XmlDictionaryWriter writer)
 {
     writer.WriteStartElement(this.coordinationStrings.Prefix, this.coordinationXmlDictionaryStrings.Register, this.coordinationXmlDictionaryStrings.Namespace);
     XmlDictionaryString str = WSAtomicTransactionStrings.ProtocolToWellKnownName(this.Protocol, this.protocolVersion);
     writer.WriteStartElement(this.coordinationXmlDictionaryStrings.Protocol, this.coordinationXmlDictionaryStrings.Namespace);
     writer.WriteString(str);
     writer.WriteEndElement();
     this.ParticipantProtocolService.WriteTo(MessagingVersionHelper.AddressingVersion(this.protocolVersion), writer, this.coordinationXmlDictionaryStrings.ParticipantProtocolService, this.coordinationXmlDictionaryStrings.Namespace);
     if (this.Loopback != Guid.Empty)
     {
         writer.WriteStartElement("mstx", XD.DotNetAtomicTransactionExternalDictionary.Loopback, XD.DotNetAtomicTransactionExternalDictionary.Namespace);
         writer.WriteValue(this.Loopback);
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
 public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
 {
     this.CheckObjectValidity();
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Action, samlDictionary.Namespace);
     if (this.ns != null)
     {
         writer.WriteStartAttribute(samlDictionary.ActionNamespaceAttribute, null);
         writer.WriteString(this.ns);
         writer.WriteEndAttribute();
     }
     writer.WriteString(this.action);
     writer.WriteEndElement();
 }
 protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     writer.WriteStartElement(SECURITY_PREFIX, AUTHID_ELEMENT_NAME, SECURITY_NAMESPACE);
     writer.WriteString(AuthID);
     writer.WriteEndElement();
 }
Example #14
0
 public override void WriteString(string text)
 {
     writer.WriteString(text);
 }
Example #15
0
		internal static void Serialize(MessageDictionary messageDictionary, XmlDictionaryWriter writer) {
			Requires.NotNull(messageDictionary, "messageDictionary");
			Requires.NotNull(writer, "writer");

			writer.WriteStartElement("root");
			writer.WriteAttributeString("type", "object");
			foreach (var pair in messageDictionary) {
				bool include = false;
				string type = "string";
				MessagePart partDescription;
				if (messageDictionary.Description.Mapping.TryGetValue(pair.Key, out partDescription)) {
					Contract.Assume(partDescription != null);
					if (partDescription.IsRequired || partDescription.IsNondefaultValueSet(messageDictionary.Message)) {
						include = true;
						Type formattingType = partDescription.PreferredFormattingType;
						if (IsNumeric(formattingType)) {
							type = "number";
						} else if (formattingType.IsAssignableFrom(typeof(bool))) {
							type = "boolean";
						}
					}
				} else {
					// This is extra data.  We always write it out.
					include = true;
				}

				if (include) {
					writer.WriteStartElement(pair.Key);
					writer.WriteAttributeString("type", type);
					writer.WriteString(pair.Value);
					writer.WriteEndElement();
				}
			}

			writer.WriteEndElement();
		}
        public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
        {
            CheckObjectValidity();

            if (writer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer");

            if (samlSerializer == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));

#pragma warning suppress 56506 // samlSerializer.DictionaryManager is never null.
            SamlDictionary dictionary = samlSerializer.DictionaryManager.SamlDictionary;

            try
            {
                writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.Assertion, dictionary.Namespace);

                writer.WriteStartAttribute(dictionary.MajorVersion, null);
                writer.WriteValue(SamlConstants.MajorVersionValue);
                writer.WriteEndAttribute();
                writer.WriteStartAttribute(dictionary.MinorVersion, null);
                writer.WriteValue(SamlConstants.MinorVersionValue);
                writer.WriteEndAttribute();
                writer.WriteStartAttribute(dictionary.AssertionId, null);
                writer.WriteString(this.assertionId);
                writer.WriteEndAttribute();
                writer.WriteStartAttribute(dictionary.Issuer, null);
                writer.WriteString(this.issuer);
                writer.WriteEndAttribute();
                writer.WriteStartAttribute(dictionary.IssueInstant, null);
                writer.WriteString(this.issueInstant.ToString(SamlConstants.GeneratedDateTimeFormat, CultureInfo.InvariantCulture));
                writer.WriteEndAttribute();

                // Write out conditions
                if (this.conditions != null)
                {
                    this.conditions.WriteXml(writer, samlSerializer, keyInfoSerializer);
                }

                // Write out advice if there is one
                if (this.advice != null)
                {
                    this.advice.WriteXml(writer, samlSerializer, keyInfoSerializer);
                }

                for (int i = 0; i < this.statements.Count; i++)
                {
                    this.statements[i].WriteXml(writer, samlSerializer, keyInfoSerializer);
                }

                writer.WriteEndElement();
            }
            catch (Exception e)
            {
                // Always immediately rethrow fatal exceptions.
                if (Fx.IsFatal(e)) throw;

                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SAMLTokenNotSerialized), e));
            }
        }
            public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
            {
                bool isEmptyElement;
                if (writer == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
                }
                if (!this.MoveToFirst())
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.IdentityModel.SR.GetString("XmlTokenBufferIsEmpty")));
                }
                int num = 0;
                int num2 = -1;
                bool flag = true;
            Label_0040:
                switch (this.NodeType)
                {
                    case XmlNodeType.Element:
                        isEmptyElement = this.IsEmptyElement;
                        num++;
                        if (flag)
                        {
                            if (this.excludedElementDepth.HasValue)
                            {
                                int? excludedElementDepth = this.excludedElementDepth;
                                int num3 = num - 1;
                                if (!((excludedElementDepth.GetValueOrDefault() == num3) && excludedElementDepth.HasValue))
                                {
                                    break;
                                }
                            }
                            if ((this.LocalName == this.excludedElement) && (this.NamespaceUri == this.excludedElementNamespace))
                            {
                                flag = false;
                                num2 = num;
                            }
                        }
                        break;

                    case XmlNodeType.Text:
                        if (flag)
                        {
                            writer.WriteString(this.Value);
                        }
                        goto Label_01AD;

                    case XmlNodeType.CDATA:
                        if (flag)
                        {
                            writer.WriteCData(this.Value);
                        }
                        goto Label_01AD;

                    case XmlNodeType.Comment:
                        if (flag)
                        {
                            writer.WriteComment(this.Value);
                        }
                        goto Label_01AD;

                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        if (flag)
                        {
                            writer.WriteWhitespace(this.Value);
                        }
                        goto Label_01AD;

                    case XmlNodeType.EndElement:
                        goto Label_0152;

                    default:
                        goto Label_01AD;
                }
                if (flag)
                {
                    writer.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceUri);
                }
                if (this.MoveToFirstAttribute())
                {
                    do
                    {
                        if (flag)
                        {
                            writer.WriteAttributeString(this.Prefix, this.LocalName, this.NamespaceUri, this.Value);
                        }
                    }
                    while (this.MoveToNextAttribute());
                }
                if (!isEmptyElement)
                {
                    goto Label_01AD;
                }
            Label_0152:
                if (flag)
                {
                    writer.WriteEndElement();
                }
                else if (num2 == num)
                {
                    flag = true;
                    num2 = -1;
                }
                num--;
            Label_01AD:
                if (this.MoveToNext())
                {
                    goto Label_0040;
                }
            }
 public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.SignatureValue, dictionaryManager.XmlSignatureDictionary.Namespace);
     if (this.id != null)
     {
         writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.id);
     }
     if (this.signatureText != null)
     {
         writer.WriteString(this.signatureText);
     }
     else
     {
         writer.WriteBase64(this.signatureValue, 0, this.signatureValue.Length);
     }
     writer.WriteEndElement();
 }
 public void WriteValue(XmlDictionaryWriter writer, object value)
 {
     if (_isArray)
     {
         switch (_typeCode)
         {
             case TypeCode.Byte:
                 {
                     byte[] arrayValue = (byte[])value;
                     writer.WriteBase64(arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Boolean:
                 {
                     bool[] arrayValue = (bool[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.DateTime:
                 {
                     DateTime[] arrayValue = (DateTime[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Decimal:
                 {
                     decimal[] arrayValue = (decimal[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Int32:
                 {
                     Int32[] arrayValue = (Int32[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Int64:
                 {
                     Int64[] arrayValue = (Int64[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Single:
                 {
                     float[] arrayValue = (float[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             case TypeCode.Double:
                 {
                     double[] arrayValue = (double[])value;
                     writer.WriteArray(null, _itemName, _itemNamespace, arrayValue, 0, arrayValue.Length);
                 }
                 break;
             default:
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxInvalidUseOfPrimitiveOperationFormatter));
         }
     }
     else
     {
         switch (_typeCode)
         {
             case TypeCode.Boolean:
                 writer.WriteValue((bool)value);
                 break;
             case TypeCode.DateTime:
                 writer.WriteValue((DateTime)value);
                 break;
             case TypeCode.Decimal:
                 writer.WriteValue((Decimal)value);
                 break;
             case TypeCode.Double:
                 writer.WriteValue((double)value);
                 break;
             case TypeCode.Int32:
                 writer.WriteValue((int)value);
                 break;
             case TypeCode.Int64:
                 writer.WriteValue((long)value);
                 break;
             case TypeCode.Single:
                 writer.WriteValue((float)value);
                 break;
             case TypeCode.String:
                 writer.WriteString((string)value);
                 break;
             default:
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxInvalidUseOfPrimitiveOperationFormatter));
         }
     }
 }
		public void WriteContentsTo (
			AddressingVersion addressingVersion,
			XmlDictionaryWriter writer)
		{
#if NET_2_1
			writer.WriteString (Uri.AbsoluteUri);
#else
			if (addressingVersion == AddressingVersion.WSAddressing10) {
				((IXmlSerializable) EndpointAddress10.FromEndpointAddress (this)).WriteXml (writer);
			} else {
				writer.WriteString (Uri.AbsoluteUri);
			}
#endif
		}
        public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
        {
            string prefix = XmlSignatureStrings.Prefix;
            XmlDictionaryString ns = dictionaryManager.XmlSignatureDictionary.Namespace;

            writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.SignedInfo, ns);
            if (this.Id != null)
            {
                writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.Id);
            }
            WriteCanonicalizationMethod(writer, dictionaryManager);
            WriteSignatureMethod(writer, dictionaryManager);
            for (int i = 0; i < this.count; i++)
            {
                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Reference, ns);
                writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.URI, null);
                writer.WriteString("#");
                writer.WriteString(this.references[i].id);
                writer.WriteEndAttribute();

                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transforms, ns);
                if (this.addEnvelopedSignatureTransform)
                {
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(dictionaryManager.XmlSignatureDictionary.EnvelopedSignature);
                    writer.WriteEndAttribute();
                    writer.WriteEndElement(); // Transform
                }

                if (this.references[i].useStrTransform)
                {
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(SecurityAlgorithms.StrTransform);
                    writer.WriteEndAttribute();
                    writer.WriteStartElement(XmlSignatureStrings.SecurityJan2004Prefix, XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace);  //<wsse:TransformationParameters>
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n);
                    writer.WriteEndAttribute();
                    writer.WriteEndElement(); //CanonicalizationMethod 
                    writer.WriteEndElement(); // TransformationParameters
                    writer.WriteEndElement(); // Transform
                }
                else
                {
                    writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, ns);
                    writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                    writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n);
                    writer.WriteEndAttribute();
                    writer.WriteEndElement(); // Transform
                }

                writer.WriteEndElement(); // Transforms

                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestMethod, ns);
                writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
                if (this.digestMethodDictionaryString != null)
                {
                    writer.WriteString(this.digestMethodDictionaryString);
                }
                else
                {
                    writer.WriteString(this.digestMethod);
                }
                writer.WriteEndAttribute();
                writer.WriteEndElement(); // DigestMethod

                byte[] digest = this.references[i].digest;
                writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestValue, ns);
                writer.WriteBase64(digest, 0, digest.Length);
                writer.WriteEndElement(); // DigestValue

                writer.WriteEndElement(); // Reference
            }
            writer.WriteEndElement(); // SignedInfo
        }
Example #22
0
			protected override void OnWriteBodyContents (XmlDictionaryWriter writer)
			{
				writer.WriteString ("-- message body is raw binary --");
			}
    private static void SimulateWriteFragment(XmlDictionaryWriter writer, bool useFragmentAPI, int nestedLevelsLeft)
    {
        if (nestedLevelsLeft <= 0)
        {
            return;
        }

        Random rndGen = new Random(nestedLevelsLeft);
        int signatureLen = rndGen.Next(100, 200);
        byte[] signature = new byte[signatureLen];
        rndGen.NextBytes(signature);

        MemoryStream fragmentStream = new MemoryStream();

        if (!useFragmentAPI) // simulating in the writer itself
        {
            writer.WriteStartElement("SignatureValue_" + nestedLevelsLeft);
            writer.WriteBase64(signature, 0, signatureLen);
            writer.WriteEndElement();
        }

        if (useFragmentAPI)
        {
            FragmentHelper.Start(writer, fragmentStream);
        }

        writer.WriteStartElement("Fragment" + nestedLevelsLeft);
        for (int i = 0; i < 5; i++)
        {
            writer.WriteStartElement(String.Format("Element{0}_{1}", nestedLevelsLeft, i));
            writer.WriteAttributeString("attr1", "value1");
            writer.WriteAttributeString("attr2", "value2");
        }
        writer.WriteString("This is a text with unicode characters: <>&;\u0301\u2234");
        for (int i = 0; i < 5; i++)
        {
            writer.WriteEndElement();
        }

        // write other nested fragments...
        SimulateWriteFragment(writer, useFragmentAPI, nestedLevelsLeft - 1);

        writer.WriteEndElement(); // Fragment{nestedLevelsLeft}
        writer.Flush();

        if (useFragmentAPI)
        {
            FragmentHelper.End(writer);
            writer.WriteStartElement("SignatureValue_" + nestedLevelsLeft);
            writer.WriteBase64(signature, 0, signatureLen);
            writer.WriteEndElement();

            FragmentHelper.Write(writer, fragmentStream.GetBuffer(), 0, (int)fragmentStream.Length);

            writer.Flush();
        }
    }
Example #24
0
 protected override void OnWriteHeaderContents(System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     writer.WriteString(value);
 }
Example #25
0
 protected override void OnWriteHeaderContents(XmlDictionaryWriter xmlDictionaryWriter, MessageVersion messageVersion)
 {
     xmlDictionaryWriter.WriteString(value);
 }
 public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, dictionaryManager.XmlSignatureDictionary.Namespace);
     writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
     writer.WriteString(this.Algorithm);
     writer.WriteEndAttribute();
     this.transformationParameters.WriteTo(writer, dictionaryManager);
     writer.WriteEndElement(); // Transform
 }
 public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer)
 {
     this.CheckObjectValidity();
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
     }
     if (samlSerializer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer"));
     }
     SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary;
     writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.Subject, samlDictionary.Namespace);
     if (this.name != null)
     {
         writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.NameIdentifier, samlDictionary.Namespace);
         if (this.nameFormat != null)
         {
             writer.WriteStartAttribute(samlDictionary.NameIdentifierFormat, null);
             writer.WriteString(this.nameFormat);
             writer.WriteEndAttribute();
         }
         if (this.nameQualifier != null)
         {
             writer.WriteStartAttribute(samlDictionary.NameIdentifierNameQualifier, null);
             writer.WriteString(this.nameQualifier);
             writer.WriteEndAttribute();
         }
         writer.WriteString(this.name);
         writer.WriteEndElement();
     }
     if (this.confirmationMethods.Count > 0)
     {
         writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.SubjectConfirmation, samlDictionary.Namespace);
         foreach (string str in this.confirmationMethods)
         {
             writer.WriteElementString(samlDictionary.SubjectConfirmationMethod, samlDictionary.Namespace, str);
         }
         if (!string.IsNullOrEmpty(this.confirmationData))
         {
             writer.WriteElementString(samlDictionary.SubjectConfirmationData, samlDictionary.Namespace, this.confirmationData);
         }
         if (this.securityKeyIdentifier != null)
         {
             SamlSerializer.WriteSecurityKeyIdentifier(XmlDictionaryWriter.CreateDictionaryWriter(writer), this.securityKeyIdentifier, keyInfoSerializer);
         }
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
 public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     writer.WriteStartElement(XmlSignatureStrings.SecurityJan2004Prefix, XmlSignatureStrings.TransformationParameters, XmlSignatureStrings.SecurityJan2004Namespace);  //<wsse:TransformationParameters>
     writer.WriteStartElement(dictionaryManager.XmlSignatureDictionary.Prefix.Value, dictionaryManager.XmlSignatureDictionary.CanonicalizationMethod, dictionaryManager.XmlSignatureDictionary.Namespace);
     writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null);
     writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n);
     writer.WriteEndAttribute();
     writer.WriteEndElement(); // CanonicalizationMethod 
     writer.WriteEndElement(); // TransformationParameters
 }
 public static void WriteTo(XmlDictionaryWriter writer, string referredId)
 {
     writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, ElementName, NamespaceUri);
     writer.WriteStartAttribute(ReferenceList.UriAttribute, null);
     writer.WriteString("#");
     writer.WriteString(referredId);
     writer.WriteEndAttribute();
     writer.WriteEndElement();
 }
Example #30
0
        protected override void OnBodyToString(XmlDictionaryWriter writer)
        {
            long? contentLength = this.GetHttpContentLength();
            string contentString = null;

            if (this.IsRequest)
            {
                contentString = contentLength.HasValue ?
                    SR.MessageBodyIsHttpRequestMessageWithKnownContentLength(contentLength.Value) :
                    SR.MessageBodyIsHttpRequestMessageWithUnknownContentLength;
            }
            else
            {
                contentString = contentLength.HasValue ?
                    SR.MessageBodyIsHttpResponseMessageWithKnownContentLength(contentLength.Value) :
                    SR.MessageBodyIsHttpResponseMessageWithUnknownContentLength;
            }

            writer.WriteString(contentString);
        }
 public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
     }
     if (!MoveToFirst())
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.XmlTokenBufferIsEmpty)));
     }
     int depth = 0;
     int recordedDepth = -1;
     bool include = true;
     do
     {
         switch (this.NodeType)
         {
             case XmlNodeType.Element:
                 bool isEmpty = this.IsEmptyElement;
                 depth++;
                 if (include
                     && (null == excludedElementDepth || excludedElementDepth == (depth - 1))
                     && this.LocalName == this.excludedElement 
                     && this.NamespaceUri == this.excludedElementNamespace)
                 {
                     include = false;
                     recordedDepth = depth;
                 }
                 if (include)
                 {
                     writer.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceUri);
                 }
                 if (MoveToFirstAttribute())
                 {
                     do
                     {
                         if (include)
                         {
                             writer.WriteAttributeString(this.Prefix, this.LocalName, this.NamespaceUri, this.Value);
                         }
                     }
                     while (MoveToNextAttribute());
                 }
                 if (isEmpty)
                 {
                     goto case XmlNodeType.EndElement;
                 }
                 break;
             case XmlNodeType.EndElement:
                 if (include)
                 {
                     writer.WriteEndElement();
                 }
                 else if (recordedDepth == depth)
                 {
                     include = true;
                     recordedDepth = -1;
                 }
                 depth--;
                 break;
             case XmlNodeType.CDATA:
                 if (include)
                 {
                     writer.WriteCData(this.Value);
                 }
                 break;
             case XmlNodeType.Comment:
                 if (include)
                 {
                     writer.WriteComment(this.Value);
                 }
                 break;
             case XmlNodeType.Text:
                 if (include)
                 {
                     writer.WriteString(this.Value);
                 }
                 break;
             case XmlNodeType.SignificantWhitespace:
             case XmlNodeType.Whitespace:
                 if (include)
                 {
                     writer.WriteWhitespace(this.Value);
                 }
                 break;
             case XmlNodeType.DocumentType:
             case XmlNodeType.XmlDeclaration:
                 break;
         }
     }
     while (MoveToNext());
 }
 public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     writer.WriteStartElement(this.prefix ?? "", dictionaryManager.XmlSignatureDictionary.DigestValue, dictionaryManager.XmlSignatureDictionary.Namespace);
     if (this.digestText != null)
     {
         writer.WriteString(this.digestText);
     }
     else
     {
         writer.WriteBase64(this.digestValue, 0, this.digestValue.Length);
     }
     writer.WriteEndElement();
 }