private void AddBinding(XmlDictionaryWriter writer) { writer.WriteStartElement("wsdl:binding"); writer.WriteAttributeString("name", BindingName); writer.WriteAttributeString("type", "tns:" + BindingType); writer.WriteStartElement("soap:binding"); writer.WriteAttributeString("transport", TRANSPORT_SCHEMA); writer.WriteEndElement(); // soap:binding foreach (var operation in _service.Operations) { writer.WriteStartElement("wsdl:operation"); writer.WriteAttributeString("name", operation.Name); writer.WriteStartElement("soap:operation"); writer.WriteAttributeString("soapAction", operation.SoapAction); writer.WriteAttributeString("style", "document"); writer.WriteEndElement(); // soap:operation writer.WriteStartElement("wsdl:input"); writer.WriteStartElement("soap:body"); writer.WriteAttributeString("use", "literal"); writer.WriteEndElement(); // soap:body writer.WriteEndElement(); // wsdl:input writer.WriteStartElement("wsdl:output"); writer.WriteStartElement("soap:body"); writer.WriteAttributeString("use", "literal"); writer.WriteEndElement(); // soap:body writer.WriteEndElement(); // wsdl:output writer.WriteEndElement(); // wsdl:operation } writer.WriteEndElement(); // wsdl:binding }
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { CheckObjectValidity(); if (writer == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("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; writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.AuthorityBinding, dictionary.Namespace); string prefix = null; if (!string.IsNullOrEmpty(this.authorityKind.Namespace)) { writer.WriteAttributeString(String.Empty, dictionary.NamespaceAttributePrefix.Value, null, this.authorityKind.Namespace); prefix = writer.LookupPrefix(this.authorityKind.Namespace); } writer.WriteStartAttribute(dictionary.AuthorityKind, null); if (string.IsNullOrEmpty(prefix)) writer.WriteString(this.authorityKind.Name); else writer.WriteString(prefix + ":" + this.authorityKind.Name); writer.WriteEndAttribute(); writer.WriteStartAttribute(dictionary.Location, null); writer.WriteString(this.location); writer.WriteEndAttribute(); writer.WriteStartAttribute(dictionary.Binding, null); writer.WriteString(this.binding); writer.WriteEndAttribute(); writer.WriteEndElement(); }
static bool AsyncWriteBase64Test(MemoryStream ms, byte[] byteArray, Encoding encoding, MyStreamProvider myStreamProvider) { XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(ms); writer.WriteStartElement("Root"); Task writeValueBase64Asynctask = writer.WriteBase64Async(byteArray, 0, byteArray.Length); writeValueBase64Asynctask.Wait(); if (myStreamProvider.StreamReleased) { Console.WriteLine("Ok, stream released right after AsyncWriteValueBase64"); } else { Console.WriteLine("Error, stream not released after AsyncWriteValueBase64"); return(false); } writer.WriteEndElement(); writer.Flush(); return(true); }
static bool WriteTest(MemoryStream ms, ReaderWriterFactory.ReaderWriterType rwType, Encoding encoding, MyStreamProvider myStreamProvider) { XmlWriter writer = ReaderWriterFactory.CreateXmlWriter(rwType, ms, encoding); XmlDictionaryWriter writeD = writer as XmlDictionaryWriter; writeD.WriteStartElement("Root"); writeD.WriteValue(myStreamProvider); if (rwType != ReaderWriterFactory.ReaderWriterType.MTOM) { // stream should be released right after WriteValue if (myStreamProvider.StreamReleased) { Console.WriteLine("Ok, stream released right after WriteValue"); } else { Console.WriteLine("Error, stream not released after WriteValue"); return(false); } } writer.WriteEndElement(); // stream should be released now for MTOM if (rwType == ReaderWriterFactory.ReaderWriterType.MTOM) { if (myStreamProvider.StreamReleased) { Console.WriteLine("Ok, stream released right after WriteValue"); } else { Console.WriteLine("Error, stream not released after WriteValue"); return(false); } } writer.Flush(); return(true); }
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { this.CheckObjectValidity(); if (writer == null) { throw System.IdentityModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer")); } if (samlSerializer == null) { throw System.IdentityModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("samlSerializer")); } SamlDictionary samlDictionary = samlSerializer.DictionaryManager.SamlDictionary; writer.WriteStartElement(samlDictionary.PreferredPrefix.Value, samlDictionary.AuthorityBinding, samlDictionary.Namespace); string prefix = null; if (!string.IsNullOrEmpty(this.authorityKind.Namespace)) { writer.WriteAttributeString(string.Empty, samlDictionary.NamespaceAttributePrefix.Value, null, this.authorityKind.Namespace); prefix = writer.LookupPrefix(this.authorityKind.Namespace); } writer.WriteStartAttribute(samlDictionary.AuthorityKind, null); if (string.IsNullOrEmpty(prefix)) { writer.WriteString(this.authorityKind.Name); } else { writer.WriteString(prefix + ":" + this.authorityKind.Name); } writer.WriteEndAttribute(); writer.WriteStartAttribute(samlDictionary.Location, null); writer.WriteString(this.location); writer.WriteEndAttribute(); writer.WriteStartAttribute(samlDictionary.Binding, null); writer.WriteString(this.binding); writer.WriteEndAttribute(); writer.WriteEndElement(); }
/// <summary> /// When overridden in a non-abstract derived class, writes the contents of the detail element. /// </summary> /// <param name="writer">The <see cref="T:System.Xml.XmlDictionaryWriter"/> used to write the detail element.</param> protected override void OnWriteDetailContents(XmlDictionaryWriter writer) { var prefix = writer.LookupPrefix(this._nameSpace) ?? "web"; using (var reader = this._messageFault.GetReaderAtDetailContents()) { if ("Error".Equals(reader.LocalName) && string.IsNullOrWhiteSpace(reader.NamespaceURI)) { writer.WriteStartElement(prefix, "Error", this._nameSpace); reader.Read(); // ErrorMessage writer.WriteNode(reader, false); // ErrorNumber writer.WriteNode(reader, false); // writer.WriteNode(reader, false); } } }
XmlElement CreateXmlTokenElement(SecurityToken token, string prefix, string name, string ns, string usage) { Stream stream = new MemoryStream(); using (XmlDictionaryWriter xmlWriter = XmlDictionaryWriter.CreateTextWriter(stream, Encoding.UTF8, false)) { xmlWriter.WriteStartElement(prefix, name, ns); WriteToken(xmlWriter, token, usage); xmlWriter.WriteEndElement(); xmlWriter.Flush(); } stream.Seek(0, SeekOrigin.Begin); XmlDocument dom = new XmlDocument(); dom.PreserveWhitespace = true; dom.Load(stream); stream.Close(); return(dom.DocumentElement); }
public virtual void WriteClaimType(XmlDictionaryWriter writer, ClaimType claimType) { if (claimType == null) { return; } writer.WriteStartElement(Elements.ClaimType, Namespace); if (!writer.TryWriteAttributeValue(Attributes.Uri, claimType.Uri)) { throw XmlWriterExceptionHelper.CreateRequiredAttributeMissingException(Elements.ClaimType, Attributes.Uri); } _ = writer.TryWriteAttributeValue(Attributes.Optional, claimType.Optional); _ = writer.TryWriteElementValue(Elements.DisplayName, Namespace, claimType.DisplayName); _ = writer.TryWriteElementValue(Elements.Description, Namespace, claimType.Description); _ = writer.TryWriteElementValue(Elements.DisplayValue, Namespace, claimType.DisplayValue); _ = writer.TryWriteElementValue(Elements.Value, Namespace, claimType.Value); writer.WriteEndElement(); }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { writer.WriteStartElement("Binary"); if (IsStreamed) { byte[] buffer = new byte[1000]; int bytesRead; do { bytesRead = this.stream.Read(buffer, 0, buffer.Length); if (bytesRead > 0) { writer.WriteBase64(buffer, 0, bytesRead); } } while (bytesRead > 0); } else { writer.WriteBase64(this.buffer.Array, this.buffer.Offset, this.buffer.Count); } writer.WriteEndElement(); }
protected override void SerializeBody(XmlDictionaryWriter writer, MessageVersion version, string action, MessageDescription messageDescription, object returnValue, object[] parameters, bool isRequest) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(writer))); } if (parameters == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(parameters))); } MessageInfo messageInfo; if (isRequest) { messageInfo = requestMessageInfo; } else { messageInfo = replyMessageInfo; } if (messageInfo.WrapperName != null) { writer.WriteStartElement(messageInfo.WrapperName, messageInfo.WrapperNamespace); } if (messageInfo.ReturnPart != null) { SerializeParameter(writer, messageInfo.ReturnPart, returnValue); } SerializeParameters(writer, messageInfo.BodyParts, parameters); if (messageInfo.WrapperName != null) { writer.WriteEndElement(); } }
public void WriteTo(AddressingVersion addressingVersion, XmlDictionaryWriter writer, XmlDictionaryString localName, XmlDictionaryString ns) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } if (addressingVersion == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("addressingVersion"); } if (localName == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("localName"); } if (ns == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("ns"); } writer.WriteStartElement(localName, ns); this.WriteContentsTo(addressingVersion, writer); writer.WriteEndElement(); }
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("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; writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.Conditions, dictionary.Namespace); if (this.notBefore != SecurityUtils.MinUtcDateTime) { writer.WriteStartAttribute(dictionary.NotBefore, null); writer.WriteString(this.notBefore.ToString(SamlConstants.GeneratedDateTimeFormat, DateTimeFormatInfo.InvariantInfo)); writer.WriteEndAttribute(); } if (this.notOnOrAfter != SecurityUtils.MaxUtcDateTime) { writer.WriteStartAttribute(dictionary.NotOnOrAfter, null); writer.WriteString(this.notOnOrAfter.ToString(SamlConstants.GeneratedDateTimeFormat, DateTimeFormatInfo.InvariantInfo)); writer.WriteEndAttribute(); } for (int i = 0; i < this.conditions.Count; i++) { this.conditions[i].WriteXml(writer, samlSerializer, keyInfoSerializer); } writer.WriteEndElement(); }
//</snippet6> //<snippet7> public static void WriteObjectContentInDocument(string path) { // Create the object to serialize. Person p = new Person("Lynn", "Tsoflias", 9876); // Create the writer. FileStream fs = new FileStream(path, FileMode.Create); XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(fs); NetDataContractSerializer ser = new NetDataContractSerializer(); // Use the writer to start a document. writer.WriteStartDocument(true); // Use the writer to write the root element. writer.WriteStartElement("Company"); // Use the writer to write an element. writer.WriteElementString("Name", "Microsoft"); // Use the serializer to write the start, content, // and end data. ser.WriteStartObject(writer, p); writer.WriteStartAttribute("localName"); writer.WriteString("My Value"); writer.WriteEndAttribute(); ser.WriteObjectContent(writer, p); ser.WriteEndObject(writer); // Use the writer to write the end element // and end of the document. writer.WriteEndElement(); writer.WriteEndDocument(); // Close and release the writer resources. writer.Flush(); fs.Flush(); fs.Close(); }
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoSerializer) { CheckObjectValidity(); if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("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; writer.WriteStartElement(dictionary.PreferredPrefix.Value, dictionary.Attribute, dictionary.Namespace); writer.WriteStartAttribute(dictionary.AttributeName, null); writer.WriteString(this.name); writer.WriteEndAttribute(); writer.WriteStartAttribute(dictionary.AttributeNamespace, null); writer.WriteString(this.nameSpace); writer.WriteEndAttribute(); for (int i = 0; i < this.attributeValues.Count; i++) { if (this.attributeValues[i] == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.SAMLAttributeValueCannotBeNull)); } writer.WriteElementString(dictionary.PreferredPrefix.Value, dictionary.AttributeValue, dictionary.Namespace, this.attributeValues[i]); } writer.WriteEndElement(); }
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(); }
public override void WriteStartElement(string prefix, string localName, string namespaceUri) { if (_isStrReferenceElement && _insertId) { if (_id != null) { _innerWriter.WriteAttributeString(XD.UtilityDictionary.Prefix.Value, XD.UtilityDictionary.IdAttribute, XD.UtilityDictionary.Namespace, _id); } _isStrReferenceElement = false; _insertId = false; } _index++; if (_index == 1 && localName == XD.SecurityJan2004Dictionary.SecurityTokenReference.Value) { _insertId = true; _isStrReferenceElement = true; } _innerWriter.WriteStartElement(prefix, localName, namespaceUri); }
public virtual void WriteXml(XmlDictionaryWriter writer, SamlSerializer samlSerializer, SecurityTokenSerializer keyInfoTokenSerializer) { if (writer == null) { throw new ArgumentNullException("writer"); } if (samlSerializer == null) { throw new ArgumentNullException("samlSerializer"); } writer.WriteStartElement("saml", "Advice", SamlConstants.Namespace); foreach (string idref in AssertionIdReferences) { writer.WriteElementString("saml", "AssertionIDReference", SamlConstants.Namespace, idref); } foreach (SamlAssertion assertion in Assertions) { assertion.WriteXml(writer, samlSerializer, keyInfoTokenSerializer); } writer.WriteEndElement(); }
public void WriteAttributeXmlns() { // equivalent to WriteXmlnsAttribute() XmlDictionaryString ds; MemoryStream ms = new MemoryStream(); XmlDictionary dic = new XmlDictionary(); XmlDictionaryWriter w = XmlDictionaryWriter.CreateBinaryWriter(ms, dic, null); w.WriteStartElement("root"); w.WriteAttributeString("xmlns", "foo", "http://www.w3.org/2000/xmlns/", "urn:foo"); w.WriteAttributeString(dic.Add("xmlns"), dic.Add("http://www.w3.org/2000/xmlns/"), "urn:bar"); w.WriteAttributeString("a", String.Empty); w.Close(); byte [] bytes = new byte [] { // 40 (root) 04 (a) A8 // 09 (foo) (urn:foo) 08 (urn:bar) 0x40, 4, 0x72, 0x6F, 0x6F, 0x74, 0x04, 1, 0x61, 0xA8, 0x09, 3, 0x66, 0x6F, 0x6F, 7, 0x75, 0x72, 0x6E, 0x3A, 0x66, 0x6F, 0x6F, 0x08, 7, 0x75, 0x72, 0x6E, 0x3A, 0x62, 0x61, 0x72, 1 }; Assert.AreEqual(bytes, ms.ToArray()); }
public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager) { writer.WriteStartElement(this.prefix, dictionaryManager.XmlSignatureDictionary.Reference, dictionaryManager.XmlSignatureDictionary.Namespace); if (this.id != null) { writer.WriteAttributeString(dictionaryManager.UtilityDictionary.IdAttribute, null, this.id); } if (this.uri != null) { writer.WriteAttributeString(dictionaryManager.XmlSignatureDictionary.URI, null, this.uri); } if (this.type != null) { writer.WriteAttributeString(dictionaryManager.XmlSignatureDictionary.Type, null, this.type); } if (this.transformChain.TransformCount > 0) { this.transformChain.WriteTo(writer, dictionaryManager); } this.digestMethodElement.WriteTo(writer, dictionaryManager); this.digestValueElement.WriteTo(writer, dictionaryManager); writer.WriteEndElement(); }
protected override void OnWriteStartEnvelope(XmlDictionaryWriter writer) { writer.WriteStartElement("wsdl", "definitions", "http://schemas.xmlsoap.org/wsdl/"); writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); if (Version == MessageVersion.Soap11 || Version == MessageVersion.Soap11WSAddressingAugust2004 || Version == MessageVersion.Soap11WSAddressingAugust2004) // Soap11 { writer.WriteAttributeString("xmlns:soap", "http://schemas.xmlsoap.org/wsdl/soap/"); } else if (Version == MessageVersion.Soap12WSAddressing10 || Version == MessageVersion.Soap12WSAddressingAugust2004) // Soap12 { writer.WriteAttributeString("xmlns:soap", "http://schemas.xmlsoap.org/wsdl/soap12/"); } else { throw new ArgumentOutOfRangeException(nameof(Version), "Unsupported MessageVersion encountered while writing envelope."); } writer.WriteAttributeString("xmlns:tns", _service.Contracts.First().Namespace); writer.WriteAttributeString("xmlns:wsam", "http://www.w3.org/2007/05/addressing/metadata"); writer.WriteAttributeString("targetNamespace", _service.Contracts.First().Namespace); writer.WriteAttributeString("name", _service.ServiceType.Name); }
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(); }
private static string ReadRawBody(ref Message message) { XmlDictionaryReader r = message.GetReaderAtBodyContents(); r.ReadStartElement("Binary"); byte[] bits = r.ReadContentAsBase64(); string msg = Encoding.UTF8.GetString(bits); MemoryStream ms = new MemoryStream(); XmlDictionaryWriter w = XmlDictionaryWriter.CreateBinaryWriter(ms); w.WriteStartElement("Binary"); w.WriteBase64(bits, 0, bits.Length); w.WriteEndElement(); w.Flush(); ms.Position = 0; XmlDictionaryReader rt = XmlDictionaryReader.CreateBinaryReader(ms, XmlDictionaryReaderQuotas.Max); Message msg2 = Message.CreateMessage(rt, int.MaxValue, message.Version); msg2.Properties.CopyProperties(message.Properties); message = msg2; return(msg); }
public void WriteBodyToEncryptThenSign(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm) { encryptedData.Id = this.securityHeader.GenerateId(); SetBodyId(); XmlDictionaryWriter encryptingWriter = XmlDictionaryWriter.CreateTextWriter(Stream.Null); // The XmlSerializer body formatter would add a // document declaration to the body fragment when a fresh writer // is provided. Hence, insert a dummy element here and capture // the body contents as a fragment. encryptingWriter.WriteStartElement("a"); MemoryStream ms = new MemoryStream(); ((IFragmentCapableXmlDictionaryWriter)encryptingWriter).StartFragment(ms, true); this.InnerMessage.WriteBodyContents(encryptingWriter); ((IFragmentCapableXmlDictionaryWriter)encryptingWriter).EndFragment(); encryptingWriter.WriteEndElement(); ms.Flush(); encryptedData.SetUpEncryption(algorithm, new ArraySegment <byte>(ms.GetBuffer(), 0, (int)ms.Length)); this.fullBodyBuffer = new XmlBuffer(int.MaxValue); XmlDictionaryWriter canonicalWriter = this.fullBodyBuffer.OpenSection(XmlDictionaryReaderQuotas.Max); canonicalWriter.StartCanonicalization(canonicalStream, false, null); WriteStartInnerMessageWithId(canonicalWriter); encryptedData.WriteTo(canonicalWriter, ServiceModelDictionaryManager.Instance); canonicalWriter.WriteEndElement(); canonicalWriter.EndCanonicalization(); canonicalWriter.Flush(); this.fullBodyBuffer.CloseSection(); this.fullBodyBuffer.Close(); this.state = BodyState.EncryptedThenSigned; }
private void AddSystemTypes(XmlDictionaryWriter writer) { if (_buildDateTimeOffset) { writer.WriteStartElement("xs:schema"); writer.WriteAttributeString("xmlns:xs", XMLNS_XS); writer.WriteAttributeString("xmlns:tns", SYSTEM_NS); writer.WriteAttributeString("elementFormDefault", "qualified"); writer.WriteAttributeString("targetNamespace", SYSTEM_NS); writer.WriteStartElement("xs:import"); writer.WriteAttributeString("namespace", SERIALIZATION_NS); writer.WriteEndElement(); writer.WriteStartElement("xs:complexType"); writer.WriteAttributeString("name", "DateTimeOffset"); writer.WriteStartElement("xs:annotation"); writer.WriteStartElement("xs:appinfo"); writer.WriteElementString("IsValueType", SERIALIZATION_NS, "true"); writer.WriteEndElement(); // xs:appinfo writer.WriteEndElement(); // xs:annotation writer.WriteStartElement("xs:sequence"); AddSchemaType(writer, typeof(DateTime), "DateTime", false); AddSchemaType(writer, typeof(short), "OffsetMinutes", false); writer.WriteEndElement(); // xs:sequence writer.WriteEndElement(); // xs:complexType writer.WriteStartElement("xs:element"); writer.WriteAttributeString("name", "DateTimeOffset"); writer.WriteAttributeString("nillable", "true"); writer.WriteAttributeString("type", "tns:DateTimeOffset"); writer.WriteEndElement(); writer.WriteEndElement(); // xs:schema } }
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion) { var tokenPassport = _provider.GetTokenPassport(); if (tokenPassport == null) { throw new InvalidOperationException("The Credentials Provider provided null credentials"); } writer.WriteElementString(nameof(tokenPassport.account), SuiteTalkSchemas.Core, tokenPassport.account); writer.WriteElementString(nameof(tokenPassport.consumerKey), SuiteTalkSchemas.Core, tokenPassport.consumerKey); writer.WriteElementString(nameof(tokenPassport.nonce), SuiteTalkSchemas.Core, tokenPassport.nonce); if (tokenPassport.signature != null) { writer.WriteStartElement(nameof(tokenPassport.signature), SuiteTalkSchemas.Core); writer.WriteAttributeString(nameof(tokenPassport.signature.algorithm), tokenPassport.signature.algorithm); writer.WriteValue(tokenPassport.signature.Value); writer.WriteEndElement(); } writer.WriteElementString(nameof(tokenPassport.timestamp), SuiteTalkSchemas.Core, tokenPassport.timestamp.ToString()); writer.WriteElementString(nameof(tokenPassport.token), SuiteTalkSchemas.Core, tokenPassport.token); }
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion) { if (_basicPassportProvider == null) { throw new InvalidOperationException("The PassportProvider has not been set."); } var credentials = _basicPassportProvider.GetPassport(); if (credentials == null) { throw new InvalidOperationException("The Credentials Provider provided null credentials"); } writer.WriteElementString(nameof(credentials.email), SuiteTalkSchemas.Core, credentials.email); writer.WriteElementString(nameof(credentials.password), SuiteTalkSchemas.Core, credentials.password); writer.WriteElementString(nameof(credentials.account), SuiteTalkSchemas.Core, credentials.account); if (credentials.role != null) { writer.WriteStartElement(nameof(credentials.role), SuiteTalkSchemas.Core); writer.WriteElementString(nameof(credentials.role.internalId), credentials.role.internalId); writer.WriteEndElement(); } }
/// <summary>Called when the message body is written to an XML file.</summary> /// <param name="writer"> /// An <see cref="XmlDictionaryWriter"/> that is used to write this /// message body to an XML file. /// </param> protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { Debug.Assert(writer != null, "writer != null"); try { writer.WriteStartElement(ServiceUtils.WcfBinaryElementName); using (XmlWriterStream stream = new XmlWriterStream(writer)) { this.writerAction(stream); } writer.WriteEndElement(); } finally { // We will always abort the channel in case a domain service exception occurs. var ctx = System.ServiceModel.OperationContext.Current; if (ctx != null) { ctx.Channel.Abort(); } } }
public override void WriteKeyIdentifierClauseCore(XmlDictionaryWriter writer, SecurityKeyIdentifierClause keyIdentifierClause) { X509RawDataKeyIdentifierClause x509Clause = keyIdentifierClause as X509RawDataKeyIdentifierClause; if (x509Clause != null) { writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509Data, NamespaceUri); writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509Certificate, NamespaceUri); byte[] certBytes = x509Clause.GetX509RawData(); writer.WriteBase64(certBytes, 0, certBytes.Length); writer.WriteEndElement(); writer.WriteEndElement(); } X509IssuerSerialKeyIdentifierClause issuerSerialClause = keyIdentifierClause as X509IssuerSerialKeyIdentifierClause; if (issuerSerialClause != null) { writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509Data, XD.XmlSignatureDictionary.Namespace); writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509IssuerSerial, XD.XmlSignatureDictionary.Namespace); writer.WriteElementString(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509IssuerName, XD.XmlSignatureDictionary.Namespace, issuerSerialClause.IssuerName); writer.WriteElementString(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.X509SerialNumber, XD.XmlSignatureDictionary.Namespace, issuerSerialClause.IssuerSerialNumber); writer.WriteEndElement(); writer.WriteEndElement(); return; } X509SubjectKeyIdentifierClause skiClause = keyIdentifierClause as X509SubjectKeyIdentifierClause; if (skiClause != null) { writer.WriteStartElement(XmlSignatureConstants.Prefix, XmlSignatureConstants.Elements.X509Data, XmlSignatureConstants.Namespace); writer.WriteStartElement(XmlSignatureConstants.Prefix, XmlSignatureConstants.Elements.X509SKI, XmlSignatureConstants.Namespace); byte[] ski = skiClause.GetX509SubjectKeyIdentifier(); writer.WriteBase64(ski, 0, ski.Length); writer.WriteEndElement(); writer.WriteEndElement(); return; } }
private void WriteSoap12Fault(XmlDictionaryWriter writer) { // NOTE: This default culture is a hack until a better localisation solution is // built. At this stage it assumes the current thread culture var defaultCulture = CultureInfo.CurrentCulture; var faultString = _faultStringOverride ?? (_exception.InnerException != null ? _exception.InnerException.Message : _exception.Message); var faultDetail = ExtractFaultDetailsAsXmlElement(_exception); var prefix = writer.LookupPrefix(Namespaces.SOAP12_ENVELOPE_NS) ?? "s"; writer.WriteStartElement(prefix, "Fault", Namespaces.SOAP12_ENVELOPE_NS); writer.WriteStartElement(prefix, "Code", Namespaces.SOAP12_ENVELOPE_NS); writer.WriteStartElement(prefix, "Value", Namespaces.SOAP12_ENVELOPE_NS); writer.WriteString(prefix + ":Sender"); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteStartElement(prefix, "Reason", Namespaces.SOAP12_ENVELOPE_NS); writer.WriteStartElement(prefix, "Text", Namespaces.SOAP12_ENVELOPE_NS); writer.WriteAttributeString("xml", "lang", null, defaultCulture.IetfLanguageTag); writer.WriteString(faultString); writer.WriteEndElement(); writer.WriteEndElement(); if (faultDetail != null) { writer.WriteStartElement(prefix, "Detail", Namespaces.SOAP12_ENVELOPE_NS); faultDetail.WriteTo(writer); writer.WriteEndElement(); } writer.WriteEndElement(); }
public void WriteContentsTo( AddressingVersion addressingVersion, XmlDictionaryWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } #if NET_2_1 if (addressingVersion == AddressingVersion.None) { writer.WriteString(Uri.AbsoluteUri); } else { writer.WriteStartElement("Address", addressingVersion.Namespace); writer.WriteString(Uri.AbsoluteUri); writer.WriteEndElement(); } #else if (addressingVersion == AddressingVersion.None) { writer.WriteString(Uri.AbsoluteUri); } else { writer.WriteStartElement("Address", addressingVersion.Namespace); writer.WriteString(Uri.AbsoluteUri); writer.WriteEndElement(); if (Identity == null) { return; } if (Headers != null) { foreach (AddressHeader ah in Headers) { ah.WriteAddressHeader(writer); } } writer.WriteStartElement("Identity", Constants.WsaIdentityUri); X509CertificateEndpointIdentity x509 = Identity as X509CertificateEndpointIdentity; if (x509 != null) { KeyInfo ki = new KeyInfo(); KeyInfoX509Data x = new KeyInfoX509Data(); foreach (X509Certificate2 cert in x509.Certificates) { x.AddCertificate(cert); } ki.AddClause(x); ki.GetXml().WriteTo(writer); } else { DataContractSerializer ds = new DataContractSerializer(Identity.IdentityClaim.GetType()); ds.WriteObject(writer, Identity.IdentityClaim); } writer.WriteEndElement(); } #endif }
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion) { writer.WriteRaw(GetToken().OuterXml); writer.WriteStartElement("Timestamp"); writer.WriteXmlnsAttribute("", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"); writer.WriteAttributeString("Id", "Timestamp-79"); //Created writer.WriteStartElement("Created"); writer.WriteString(this.token.ValidFrom.ToString("yyyy-MM-ddTHH:mm:ssZ")); writer.WriteEndElement(); //Expires writer.WriteStartElement("Expires"); writer.WriteString(this.token.ValidTo.ToString("yyyy-MM-ddTHH:mm:ssZ")); writer.WriteEndElement(); writer.WriteEndElement(); }