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(); }
private static void DumpEncoderSize(System.Xml.XmlDictionaryWriter writer, Message copy) { var ms = new MemoryStream(); string configuredEncoder = string.Empty; if (writer is IXmlTextWriterInitializer) { var w = (IXmlTextWriterInitializer)writer; w.SetOutput(ms, Encoding.UTF8, true); configuredEncoder = "Text"; } else if (writer is IXmlMtomWriterInitializer) { var w = (IXmlMtomWriterInitializer)writer; w.SetOutput(ms, Encoding.UTF8, int.MaxValue, "", null, null, true, false); configuredEncoder = "MTOM"; } else if (writer is IXmlBinaryWriterInitializer) { var w = (IXmlBinaryWriterInitializer)writer; w.SetOutput(ms, null, null, false); configuredEncoder = "Binary"; } copy.WriteMessage(writer); writer.Flush(); var size = ms.Position; Console.WriteLine("Message size using configured ({1}) encoder {0}", size, configuredEncoder); }
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) { XmlWriterSettings setting = new XmlWriterSettings(); setting.NewLineHandling = NewLineHandling.Entitize; setting.CheckCharacters = false; if (!string.IsNullOrEmpty(body)) { writer.WriteRaw(body); } if (doc != null) { doc.WriteContentTo(writer); writer.Flush(); } }
/// <summary> /// Called when the message body is written to an XML file. /// </summary> /// <param name="writer"> /// A <see cref="T:System.Xml.XmlDictionaryWriter"/> that is used to write this message body to an /// XML file. /// </param> protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { try { this._controller.StreamTo(writer, this._actions); writer.Flush(); } catch (Exception e) { _logger.Error(e.Message, e); throw this._exceptionHandler(e); } }
/// <summary> /// Saves the object graph which represents this expression using the specified <see cref="XmlDictionaryWriter"/>. /// </summary> /// <param name="writer">An <see cref="XmlDictionaryWriter"/> used to write the object graph.</param> public void Save(XmlDictionaryWriter writer) { Serializer.WriteObject(writer, this.Node); writer.Flush(); }
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(); } }
/// <summary> /// Called when the message body is written to an XML file. /// </summary> /// <param name="writer"> /// A <see cref="T:System.Xml.XmlDictionaryWriter"/> that is used to write this message body to an /// XML file. /// </param> protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { try { this._controller.StreamTo(writer, this._actions); writer.Flush(); } catch (SdmxResponseSizeExceedsLimitException e) { // error is on payload. _logger.Warn(e.Message, e); writer.Flush(); } catch (SdmxResponseTooLargeException e) { // error is on payload. _logger.Warn(e.Message, e); writer.Flush(); } catch (Exception e) { _logger.Error(e.Message, e); throw this._exceptionHandler(e); } }
void WriteCanonicalizedBodyWithFragments(Stream canonicalStream, XmlDictionaryWriter writer) { byte[] buffer = null; if (this.discoveryInfo.SupportsInclusivePrefixes) { buffer = this.BufferBodyAndGetInclusivePrefixes(); } using (MemoryStream bodyBufferStream = new MemoryStream()) { writer.StartCanonicalization(canonicalStream, false, this.inclusivePrefixes); IFragmentCapableXmlDictionaryWriter fragmentingWriter = (IFragmentCapableXmlDictionaryWriter)writer; fragmentingWriter.StartFragment(bodyBufferStream, false); this.WriteBufferOrMessageBody(writer, buffer); fragmentingWriter.EndFragment(); writer.EndCanonicalization(); writer.Flush(); this.fullBodyFragmentLength = (int)bodyBufferStream.Length; this.fullBodyFragment = bodyBufferStream.ToArray(); } }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { try { do { switch (reader.NodeType) { case XmlNodeType.Element: writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI); for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); writer.WriteAttributeString(reader.LocalName, reader.NamespaceURI, reader.Value.Replace(sourcePattern, targetPattern)); } reader.MoveToElement(); if (reader.IsEmptyElement) { writer.WriteEndElement(); } break; case XmlNodeType.Text: writer.WriteString(reader.Value.Replace(sourcePattern, targetPattern)); break; case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: writer.WriteWhitespace(reader.Value); break; case XmlNodeType.CDATA: writer.WriteCData(reader.Value); break; case XmlNodeType.EntityReference: writer.WriteEntityRef(reader.Name); break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: writer.WriteProcessingInstruction(reader.Name, reader.Value); break; case XmlNodeType.DocumentType: writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value); break; case XmlNodeType.Comment: writer.WriteComment(reader.Value); break; case XmlNodeType.EndElement: writer.WriteFullEndElement(); break; } } while (reader.Read()); writer.Flush(); } catch (Exception ex) { Console.WriteLine(ex); throw; } }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { writer.WriteNode(JsonReaderWriterFactory.CreateJsonReader(_jsonStream, XmlDictionaryReaderQuotas.Max), false); writer.Flush(); }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { if (!IsEmpty) { if (!isInboundRequest) { writer.WriteStartElement(IsXmlRpcMethodCall ? XmlRpcProtocol.MethodCall : XmlRpcProtocol.MethodResponse); if (IsXmlRpcMethodCall) { writer.WriteStartElement(XmlRpcProtocol.MethodName); writer.WriteString((string)properties["XmlRpcMethodName"]); writer.WriteEndElement(); } } writer.WriteNode(bodyReader, true); if (!isInboundRequest) { writer.WriteEndElement(); } writer.Flush(); } }
public override void Flush() { writer.Flush(); }
private void WriteHeader(XmlDictionaryWriter writer) { //Begin Variable setups var nonce = new byte[64]; RandomNumberGenerator.Create().GetBytes(nonce); string created = DateTime.Now.ToString("yyyy-MM-ddThh:mm:ss.msZ"); //End Variable setups // Write Namespace attributes on the "wsse:Security" Node writer.WriteXmlnsAttribute("wsse", "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"); // Begin UsernameToken Holder for UserName, Password, Nonce, and Created Nodes writer.WriteStartElement("wsse", "UsernameToken", null); writer.WriteAttributeString("wsu", "Id", null, "UsernameToken-2"); //Begin Username writer.WriteStartElement("wsse", "Username", null); writer.WriteString(SystemUser); writer.WriteEndElement(); //End Username //Begin Password Plaintext writer.WriteStartElement("wsse", "Password", null); if (this.SystermPasswordType == PasswordType.ClearText) { writer.WriteAttributeString("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"); writer.WriteString(SystemPassword); } else if (this.SystermPasswordType == PasswordType.Digest) { 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 Plaintext //Begin Password Nonce 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 Password Nonce //Begin Created writer.WriteStartElement("wsu", "Created", null); writer.WriteString(created); writer.WriteEndElement(); //End Created writer.WriteEndElement(); // Begin UsernameToken Holder writer.Flush(); }
public void AddReference(string headerId, XmlDictionaryReader reader, XmlDictionaryWriter writer) { HashStream hashStream = this.TakeHashStream(); writer.StartCanonicalization(hashStream, false, this.InclusivePrefixes); // The reader must be positioned on the start element of the header / body we want to canonicalize writer.WriteNode(reader, false); writer.EndCanonicalization(); writer.Flush(); // Add a reference for this block this.AddReference(headerId, hashStream.FlushHashAndGetValue()); }
protected override void ReturnXmlWriter(XmlDictionaryWriter writer) { Contract.Assert(writer != null, "writer MUST NOT be null"); writer.Flush(); writer.Dispose(); }
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()); }
/// <summary> /// Overwrites the default SOAP Security Header values generated by WCF with /// those required by the UserService which implements WSE 2.0. This is required /// for interoperability between a WCF Client and a WSE 2.0 Service. /// </summary> /// <param name="writer"><see cref="XmlDictionaryWriter"/></param> private void WriteHeader(XmlDictionaryWriter writer) { // Create the Nonce byte[] nonce = GenerateNonce(); // Create the Created Date string created = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); // Create the WSSE Security Header, starting with the Username Element 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(config.Username); writer.WriteEndElement(); // Add the Password Element 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(GeneratePasswordDigest(nonce, created, config.Password)); writer.WriteEndElement(); // Add the Nonce Element 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(); // Lastly, add the Created Element writer.WriteStartElement("wsu", "Created", null); writer.WriteString(created); writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); }