public WriteAttributeString ( System localName, System namespaceUri, string value ) : void | ||
localName | System | |
namespaceUri | System | |
value | string | |
리턴 | void |
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(); }
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); }
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion) { if (this.wsatInfo != null) { if (this.wsatInfo.Timeout != 0) { writer.WriteAttributeString(XD.CoordinationExternalDictionary.Expires, CoordinationNamespace, XmlConvert.ToString(this.wsatInfo.Timeout)); } if (!string.IsNullOrEmpty(this.wsatInfo.Identifier)) { writer.WriteAttributeString(XD.CoordinationExternalDictionary.Identifier, CoordinationNamespace, this.wsatInfo.Identifier); } } WritePropagationTokenElement(writer, this.propagationToken); }
protected override void WriteAdditionalAttributes(XmlDictionaryWriter writer) { if (this.recipient != null) { writer.WriteAttributeString(RecipientAttribute, null, this.recipient); } }
/// <summary> /// Writes the body of an object in the output /// </summary> public override void WriteObjectContent(System.Xml.XmlDictionaryWriter writer, object graph) { if (writer == null) { throw new ArgumentNullException("writer"); } if (graph == null) { writer.WriteAttributeString("nil", "true"); } else { using (MemoryStream ms = new MemoryStream()) { if (isList) { model.Serialize(ms, graph, null); } else { using (ProtoWriter protoWriter = new ProtoWriter(ms, model, null)) { model.Serialize(key, graph, protoWriter); } } byte[] buffer = ms.GetBuffer(); writer.WriteBase64(buffer, 0, (int)ms.Length); } } }
public override void WriteKeyIdentifierClauseCore(XmlDictionaryWriter writer, SecurityKeyIdentifierClause keyIdentifierClause) { EncryptedKeyIdentifierClause clause = keyIdentifierClause as EncryptedKeyIdentifierClause; writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.EncryptedKey, this.NamespaceUri); if (clause.EncryptionMethod != null) { writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.EncryptionMethod, this.NamespaceUri); writer.WriteAttributeString(XD.XmlEncryptionDictionary.AlgorithmAttribute, null, clause.EncryptionMethod); if (clause.EncryptionMethod == XD.SecurityAlgorithmDictionary.RsaOaepKeyWrap.Value) { writer.WriteStartElement("", XD.XmlSignatureDictionary.DigestMethod, XD.XmlSignatureDictionary.Namespace); writer.WriteAttributeString(XD.XmlSignatureDictionary.Algorithm, null, "http://www.w3.org/2000/09/xmldsig#sha1"); writer.WriteEndElement(); } writer.WriteEndElement(); } if (clause.EncryptingKeyIdentifier != null) { this.tokenSerializer.WriteKeyIdentifier(writer, clause.EncryptingKeyIdentifier); } writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CipherData, this.NamespaceUri); writer.WriteStartElement(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CipherValue, this.NamespaceUri); byte[] encryptedKey = clause.GetEncryptedKey(); writer.WriteBase64(encryptedKey, 0, encryptedKey.Length); writer.WriteEndElement(); writer.WriteEndElement(); if (clause.CarriedKeyName != null) { writer.WriteElementString(XD.XmlEncryptionDictionary.Prefix.Value, XD.XmlEncryptionDictionary.CarriedKeyName, this.NamespaceUri, clause.CarriedKeyName); } writer.WriteEndElement(); }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { writer.WriteStartElement("root"); writer.WriteAttributeString("type", "object"); writer.WriteStartElement("message"); writer.WriteAttributeString("type", "string"); writer.WriteString(this.exception.Message); writer.WriteEndElement(); writer.WriteEndElement(); }
protected override void OnWriteHeaderContents( XmlDictionaryWriter writer, MessageVersion messageVersion) { if (null == writer) { throw new ArgumentNullException("writer"); } writer.WriteStartElement("Property", this.Namespace); writer.WriteAttributeString("name", null, "instanceId"); writer.WriteValue(Value); writer.WriteEndElement(); }
public override void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { string prefix = ""; XmlDictionaryString namespaceUri = dictionaryManager.XmlSignatureDictionary.Namespace; writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.SignedInfo, namespaceUri); if (base.Id != null) { writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, base.Id); } base.WriteCanonicalizationMethod(writer, dictionaryManager); base.WriteSignatureMethod(writer, dictionaryManager); for (int i = 0; i < this.count; i++) { writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Reference, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.URI, null); writer.WriteString("#"); writer.WriteString(this.references[i].id); writer.WriteEndAttribute(); writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transforms, namespaceUri); if (this.addEnvelopedSignatureTransform) { writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(dictionaryManager.XmlSignatureDictionary.EnvelopedSignature); writer.WriteEndAttribute(); writer.WriteEndElement(); } writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.Transform, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); writer.WriteString(dictionaryManager.SecurityAlgorithmDictionary.ExclusiveC14n); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestMethod, namespaceUri); writer.WriteStartAttribute(dictionaryManager.XmlSignatureDictionary.Algorithm, null); if (this.digestMethodDictionaryString != null) { writer.WriteString(this.digestMethodDictionaryString); } else { writer.WriteString(this.digestMethod); } writer.WriteEndAttribute(); writer.WriteEndElement(); byte[] digest = this.references[i].digest; writer.WriteStartElement(prefix, dictionaryManager.XmlSignatureDictionary.DigestValue, namespaceUri); writer.WriteBase64(digest, 0, digest.Length); writer.WriteEndElement(); writer.WriteEndElement(); } 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(); }
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, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.Signature, dictionaryManager.XmlSignatureDictionary.Namespace); if (this.id != null) { writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.id); } this.signedInfo.WriteTo(writer, dictionaryManager); this.signatureValueElement.WriteTo(writer, dictionaryManager); if (this.keyIdentifier != null) { this.signedXml.SecurityTokenSerializer.WriteKeyIdentifier(writer, this.keyIdentifier); } writer.WriteEndElement(); }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { writer.WriteStartElement("BaseObjectSearchRequest", "http://schemas.microsoft.com/2006/11/IdentityManagement/DirectoryAccess"); writer.WriteAttributeString("Dialect", "http://schemas.microsoft.com/2008/1/ActiveDirectory/Dialect/XPath-Level-1"); base.OnWriteBodyContents(writer); string str = writer.LookupPrefix("http://schemas.microsoft.com/2008/1/ActiveDirectory/Data"); string str1 = writer.LookupPrefix("http://schemas.microsoft.com/2008/1/ActiveDirectory"); if (this._attributeList != null) { XmlUtility.SerializeAttributeList(writer, "AttributeType", "http://schemas.microsoft.com/2006/11/IdentityManagement/DirectoryAccess", str1, str, this._attributeList); } if (this._controls != null) { DirectoryControlSerializer.Serialize(writer, this._controls); } writer.WriteEndElement(); }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { writer.WriteStartElement("AddRequest", "http://schemas.microsoft.com/2006/11/IdentityManagement/DirectoryAccess"); writer.WriteAttributeString("Dialect", "http://schemas.microsoft.com/2008/1/ActiveDirectory/Dialect/XPath-Level-1"); if (this._attributes != null) { foreach (DirectoryAttribute _attribute in this._attributes) { AttributeTypeAndValueSerializer.Serialize(writer, _attribute); } } AttributeTypeAndValueSerializer.Serialize(writer, "http://schemas.microsoft.com/2008/1/ActiveDirectory", "relativeDistinguishedName", this._relativeDistinguishedName); AttributeTypeAndValueSerializer.Serialize(writer, "http://schemas.microsoft.com/2008/1/ActiveDirectory", "container-hierarchy-parent", this._parentContainer); if (this._controls != null) { DirectoryControlSerializer.Serialize(writer, this._controls); } writer.WriteEndElement(); }
public static void JsonValueToJXML(XmlDictionaryWriter jsonWriter, JsonValue jsonValue) { if (jsonWriter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("jsonWriter"); } jsonWriter.WriteStartElement(RootElementName); if (jsonValue == null) { jsonWriter.WriteAttributeString(TypeAttributeName, NullAttributeValue); } else { jsonValue.Save(jsonWriter); } jsonWriter.WriteEndElement(); }
public override void WriteKeyIdentifierClauseCore(XmlDictionaryWriter writer, SecurityKeyIdentifierClause keyIdentifierClause) { for (int i = 0; i < this.StrEntries.Count; ++i) { if (this.StrEntries[i].SupportsCore(keyIdentifierClause)) { writer.WriteStartElement(XD.SecurityJan2004Dictionary.Prefix.Value, XD.SecurityJan2004Dictionary.SecurityTokenReference, XD.SecurityJan2004Dictionary.Namespace); string tokenTypeUri = this.GetTokenTypeUri(this.StrEntries[i], keyIdentifierClause); if (tokenTypeUri != null) { writer.WriteAttributeString(XD.SecurityXXX2005Dictionary.Prefix.Value, XD.SecurityXXX2005Dictionary.TokenTypeAttribute, XD.SecurityXXX2005Dictionary.Namespace, tokenTypeUri); } this.StrEntries[i].WriteContent(writer, keyIdentifierClause); writer.WriteEndElement(); return; } } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.StandardsManagerCannotWriteObject, keyIdentifierClause.GetType()))); }
public static void Serialize(XmlDictionaryWriter writer, IList<DirectoryControl> controls) { string str; if (controls == null || controls.Count == 0) { return; } else { writer.WriteStartElement("ad", "controls", "http://schemas.microsoft.com/2008/1/ActiveDirectory"); foreach (DirectoryControl control in controls) { byte[] value = control.GetValue(); writer.WriteStartElement("ad", "control", "http://schemas.microsoft.com/2008/1/ActiveDirectory"); writer.WriteAttributeString("type", control.Type.ToLower()); XmlDictionaryWriter xmlDictionaryWriter = writer; string str1 = "criticality"; if (control.IsCritical) { str = "true"; } else { str = "false"; } xmlDictionaryWriter.WriteAttributeString(str1, str); if (value != null && (int)value.Length > 0) { writer.WriteStartElement("ad", "controlValue", "http://schemas.microsoft.com/2008/1/ActiveDirectory"); XmlUtility.WriteXsiTypeAttribute(writer, "base64Binary"); writer.WriteBase64(value, 0, (int)value.Length); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); return; } }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { base.OnWriteBodyContents(writer); writer.WriteStartElement("ModifyRequest", "http://schemas.microsoft.com/2006/11/IdentityManagement/DirectoryAccess"); writer.WriteAttributeString("Dialect", "http://schemas.microsoft.com/2008/1/ActiveDirectory/Dialect/XPath-Level-1"); if (this._attributeMods != null) { foreach (DirectoryAttributeModification _attributeMod in this._attributeMods) { AttributeTypeAndValueSerializer.Serialize(writer, _attributeMod); } } if (this._parent != null) { AttributeTypeAndValueSerializer.Serialize(writer, ChangeOperation.Replace, "http://schemas.microsoft.com/2008/1/ActiveDirectory", "container-hierarchy-parent", this._parent); } if (this._relativeDistinguishedName != null) { AttributeTypeAndValueSerializer.Serialize(writer, ChangeOperation.Replace, "http://schemas.microsoft.com/2008/1/ActiveDirectory", "relativeDistinguishedName", this._relativeDistinguishedName); } DirectoryControlSerializer.Serialize(writer, this._controls); writer.WriteEndElement(); }
// <summary> // Write the compact signature. // </summary> // <param name="writer">The XmlDictionaryWriter where the signature is written.</param> public void WriteTo(XmlDictionaryWriter writer) { // write ds:Sig writer.WriteStartElement(this.discoveryInfo.DiscoveryPrefix, ProtocolStrings.CompactSignatureElementName, this.discoveryInfo.DiscoveryNamespace); // write Scheme attribute writer.WriteAttributeString(ProtocolStrings.CompactSignatureSchemeAttribute, this.discoveryInfo.SchemeUri); // write KeyId string keyId = this.KeyId; if (!String.IsNullOrEmpty(keyId)) { writer.WriteAttributeString(ProtocolStrings.CompactSignatureKeyIdAttribute, Utility.ToBase64String(keyId)); } // add refs based on the values from SignedInfo string references = this.GetReferencesString(); writer.WriteAttributeString(ProtocolStrings.CompactSignatureRefsAttribute, references); // write Sig writer.WriteAttributeString(ProtocolStrings.CompactSignatureElementName, this.SignatureText); // write PrefixList if (this.InclusivePrefixes != null) { writer.WriteAttributeString(ProtocolStrings.PrefixListAttribute, this.InclusivePrefixesList); } // close - </d:Sig ...> writer.WriteEndElement(); }
public void AddReference( MessageHeaders headers, int i, XmlDictionaryWriter writer, string headerId, bool idInserted) { HashStream hashStream = this.TakeHashStream(); writer.StartCanonicalization(hashStream, false, this.InclusivePrefixes); headers.WriteStartHeader(i, writer); if (idInserted) { writer.WriteAttributeString(this.discoveryInfo.DiscoveryPrefix, ProtocolStrings.IdAttributeName, this.discoveryInfo.DiscoveryNamespace, headerId); } headers.WriteHeaderContents(i, writer); writer.WriteEndElement(); writer.EndCanonicalization(); writer.Flush(); // Add a pre-digested reference for this header this.AddReference(headerId, hashStream.FlushHashAndGetValue()); }
protected override void OnWriteStartBody ( XmlDictionaryWriter writer) { var dic = Constants.SoapDictionary; writer.WriteStartElement ("s", dic.Add ("Body"), dic.Add (Version.Envelope.Namespace)); if (body_id != null) writer.WriteAttributeString ("Id", Constants.WsuNamespace, body_id); }
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 }
public override void WriteXml (XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoTokenSerializer) { if (writer == null) throw new ArgumentNullException ("writer"); if (samlSerializer == null) throw new ArgumentNullException ("samlSerializer"); if (SamlSubject == null) throw new SecurityTokenException ("SAML Subject must be set to AuthenticationStatement before it is written."); writer.WriteStartElement ("saml", "AuthenticationStatement", SamlConstants.Namespace); writer.WriteAttributeString ("AuthenticationMethod", AuthenticationMethod); writer.WriteAttributeString ("AuthenticationInstant", AuthenticationInstant.ToString (SamlConstants.DateFormat, CultureInfo.InvariantCulture)); SamlSubject.WriteXml (writer, samlSerializer, keyInfoTokenSerializer); if (DnsAddress != null || IPAddress != null) { writer.WriteStartElement ("saml", "SubjectLocality", SamlConstants.Namespace); if (IPAddress != null) writer.WriteAttributeString ("IPAddress", IPAddress); if (DnsAddress != null) writer.WriteAttributeString ("DNSAddress", DnsAddress); writer.WriteEndElement (); } writer.WriteEndElement (); }
protected override void WriteBodyAttributes(XmlDictionaryWriter writer, MessageVersion version) { writer.WriteAttributeString("xmlns", "xsi", null, XmlUtil.XmlSerializerSchemaInstanceNamespace); writer.WriteAttributeString("xmlns", "xsd", null, XmlUtil.XmlSerializerSchemaNamespace); }
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(); } }
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(); }
void WriteJsonBodyContents (XmlDictionaryWriter writer) { if (name != null) { writer.WriteStartElement ("root"); writer.WriteAttributeString ("type", "object"); } WriteObject (serializer, writer, value); if (name != null) writer.WriteEndElement (); }
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()); }
internal override void WriteSignatureConfirmation(XmlDictionaryWriter writer, string id, byte[] signature) { if (id == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("id"); } if (signature == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("signature"); } writer.WriteStartElement(XD.SecurityXXX2005Dictionary.Prefix.Value, XD.SecurityXXX2005Dictionary.SignatureConfirmation, XD.SecurityXXX2005Dictionary.Namespace); writer.WriteAttributeString(XD.UtilityDictionary.Prefix.Value, XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace, id); writer.WriteStartAttribute(XD.SecurityXXX2005Dictionary.ValueAttribute, null); writer.WriteBase64(signature, 0, signature.Length); writer.WriteEndAttribute(); writer.WriteEndElement(); }
public override void WriteStartObject ( XmlDictionaryWriter writer, object graph) { Type rootType = type; if (root_name.Value == "") throw new InvalidDataContractException ("Type '" + type.ToString () + "' cannot have a DataContract attribute Name set to null or empty string."); if (graph == null) { if (names_filled) writer.WriteStartElement (root_name.Value, root_ns.Value); else writer.WriteStartElement (root_name, root_ns); writer.WriteAttributeString ("i", "nil", XmlSchema.InstanceNamespace, "true"); return; } QName rootQName = null; XmlDictionaryString name, ns; if (DataContractResolver != null && DataContractResolver.TryResolveType (graph.GetType (), type, default_resolver, out name, out ns)) rootQName = new QName (name.Value, ns.Value); // It is error unless 1) TypeResolver resolved the type name, 2) the object is the exact type, 3) the object is known or 4) the type is primitive. if (rootQName == null && graph.GetType () != type && IsUnknownType (graph.GetType ())) throw new SerializationException (String.Format ("Type '{0}' is unexpected. The type should either be registered as a known type, or DataContractResolver should be used.", graph.GetType ())); QName instName = rootQName; rootQName = rootQName ?? known_types.GetQName (rootType); QName graph_qname = known_types.GetQName (graph.GetType ()); known_types.Add (graph.GetType ()); if (names_filled) writer.WriteStartElement (root_name.Value, root_ns.Value); else writer.WriteStartElement (root_name, root_ns); if (rootQName != graph_qname || rootQName.Namespace != KnownTypeCollection.MSSimpleNamespace && !rootType.IsEnum) //FIXME: Hack, when should the "i:type" be written? //Not used in case of enums writer.WriteXmlnsAttribute ("i", XmlSchema.InstanceNamespace); if (root_ns.Value != rootQName.Namespace) if (rootQName.Namespace != KnownTypeCollection.MSSimpleNamespace) writer.WriteXmlnsAttribute (null, rootQName.Namespace); if (rootQName == graph_qname) return; /* Different names */ known_types.Add (rootType); instName = instName ?? KnownTypeCollection.GetPredefinedTypeName (graph.GetType ()); if (instName == QName.Empty) /* Not a primitive type */ instName = graph_qname; else /* FIXME: Hack, .. see test WriteObject7 () */ instName = new QName (instName.Name, XmlSchema.Namespace); /* // disabled as it now generates extraneous i:type output. // output xsi:type as rootType is not equivalent to the graph's type. writer.WriteStartAttribute ("i", "type", XmlSchema.InstanceNamespace); writer.WriteQualifiedName (instName.Name, instName.Namespace); writer.WriteEndAttribute (); */ }
public virtual void WriteXml ( XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { if (writer == null) throw new ArgumentNullException ("writer"); if (samlSerializer == null) throw new ArgumentNullException ("samlSerializer"); if (AuthorityKind == null) throw new SecurityTokenException ("AuthorityKind must be set to SAML AuthorityBinding before being written."); if (Binding == null) throw new SecurityTokenException ("non-zero length Binding must be set to SAML AuthorityBinding before being written."); if (Location == null) throw new SecurityTokenException ("non-zero length Location must be set to SAML AuthorityBinding before being written."); writer.WriteStartElement ("saml", "AuthorityBinding", SamlConstants.Namespace); writer.WriteXmlnsAttribute (String.Empty, AuthorityKind.Namespace); writer.WriteAttributeString ("AuthorityKind", AuthorityKind.Name); writer.WriteAttributeString ("Location", Location); writer.WriteAttributeString ("Binding", Binding); writer.WriteEndElement (); }