public void WriteRaw() { w.WriteStartElement("root"); w.WriteRaw("sample"); w.WriteRaw(new char [] { '0', '1', '2', '3' }, 1, 2); w.Close(); Assert.AreEqual("\"sample12\"", ResultString); }
/// <summary> /// When overridden in a derived class, writes raw markup manually from a character buffer. /// </summary> /// <param name="buffer">Character array containing the text to write.</param> /// <param name="index">The position within the buffer indicating the start of the text to write.</param> /// <param name="count">The number of characters to write.</param> public override void WriteRaw(char[] buffer, int index, int count) { _innerWriter.WriteRaw(buffer, index, count); if (_tracingWriter != null) { _tracingWriter.WriteRaw(buffer, index, count); } }
/// <summary> /// Writes only the content of the object to the XML document or stream using the specified <see cref="T:System.Xml.XmlDictionaryWriter" />. /// </summary> /// <param name="writer">An <see cref="T:System.Xml.XmlDictionaryWriter" /> used to write the XML document or stream.</param> /// <param name="graph">The object that contains the content to write.</param> public override void WriteObjectContent(XmlDictionaryWriter writer, object graph) { if (writer != null) { writer.WriteRaw(this.securityHeader); } }
/// <summary> /// Override the method to write the content to the XML dictionary writer. /// </summary> /// <param name="writer">Specify the output destination of the content.</param> protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { MemoryStream ms = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(typeof(EnvelopeBody)); serializer.Serialize(ms, this.requestEnvelope); XmlDocument doc = new XmlDocument(); doc.LoadXml(System.Text.ASCIIEncoding.ASCII.GetString(ms.ToArray(), 0, ms.ToArray().Length)); ms.Dispose(); foreach (XmlNode node in doc.LastChild.ChildNodes) { if (node.Name == "RequestVersion") { writer.WriteRaw(node.OuterXml); } else if (node.Name == "RequestCollection") { this.WriteNode(node, writer); } else { throw new InvalidOperationException(string.Format("this element [{0}] is not expected element", node.Name)); } } }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { writer.WriteStartElement("html"); writer.WriteStartElement("head"); writer.WriteElementString("title", "Request Failed"); writer.WriteRaw(@"<style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } h1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana; font-size: 1em;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style>"); writer.WriteEndElement(); //head writer.WriteStartElement("body"); writer.WriteRaw("<div id='content'>"); writer.WriteElementString("h1", "Request Failed"); writer.WriteElementString("h3", Message); writer.WriteRaw("</div>"); writer.WriteEndElement(); //body writer.WriteEndElement(); //html }
protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion) { writer.WriteRaw(String.Format(@" <UsernameToken xmlns=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd""> <Username>user</Username> <Password Type=""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest"">pass</Password> </UsernameToken>").Trim()); }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { //developer comments: The default behaviour of the soap message //encodes the cdata tags . The encoded values will be sent to soap service and the soap request fails //therefore replacing the encoded tags var modifiedBody = body.Replace("<", "<").Replace(">", ">"); writer.WriteRaw(modifiedBody); }
public override void WriteObjectContent(XmlDictionaryWriter writer, object graph) { if (isCustomSerialization) { MemoryStream ms = new MemoryStream(); ((ICustomSerializable)graph).WriteTo(ms); char[] bytes = Encoding.UTF8.GetString(ms.ToArray()).ToCharArray(); writer.WriteRaw(bytes, 0, bytes.Length); } else { fallbackSerializer.WriteObjectContent(writer, graph); } }
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(); } }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { writer.WriteStartElement("Fault", "http://schemas.xmlsoap.org/soap/envelope/"); using (var ms = new MemoryStream()) using (var stream = new BufferedStream(ms)) { new XmlSerializer(_fault.GetType()).Serialize(ms, _fault); stream.Position = 0; using (var reader = XmlReader.Create(stream)) { reader.MoveToContent(); var value = reader.ReadInnerXml(); writer.WriteRaw(value); } } writer.WriteEndElement(); }
protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { var modifiedBody = body; if (ModifyTags != null) { foreach (var item in ModifyTags) { if ((item.Key.Trim() == "") && (item.Value.Trim() == "")) { //no need to modify } else { modifiedBody = modifiedBody.Replace(item.Key, item.Value); } } } writer.WriteRaw(modifiedBody); }
public override void WriteObjectContent(XmlDictionaryWriter writer, Object graph) { string authToken = string.Format("<UserId>00000000-0000-0000-0000-000000000000</UserId><UserName>{0}</UserName><Password>{1}</Password>", _userName, _password); writer.WriteRaw(authToken); }
private void OnWriteDataContractSerializerBodyContents(XmlDictionaryWriter writer) { Debug.Assert(_outResults != null, "Object should set empty out results"); writer.WriteStartElement(_envelopeName, _serviceNamespace); if (_result != null) { if (_result is Stream) { writer.WriteStartElement(_resultName, _serviceNamespace); WriteStream(writer, _result); writer.WriteEndElement(); } else { // When operation return type is `System.Object` the `DataContractSerializer` adds `i:type` attribute with the correct object type Type resultType = _operation.ReturnType; IEnumerable <Type> serviceKnownTypes = _operation .GetServiceKnownTypesHierarchy() .Select(x => x.Type); // When `KnownTypeAttribute` is present the `DataContractSerializer` adds `i:type` attribute with the correct object type DataContractSerializer serializer = resultType.TryGetBaseTypeWithKnownTypes(out Type resultBaseTypeWithKnownTypes) ? new DataContractSerializer(resultBaseTypeWithKnownTypes, _resultName, _serviceNamespace, serviceKnownTypes) : new DataContractSerializer(resultType, _resultName, _serviceNamespace, serviceKnownTypes); serializer.WriteObject(writer, _result); } } foreach (var outResult in _outResults) { string value = null; if (outResult.Value is Guid) { value = outResult.Value.ToString(); } else if (outResult.Value is bool) { value = outResult.Value.ToString().ToLower(); } else if (outResult.Value is string) { value = System.Security.SecurityElement.Escape(outResult.Value.ToString()); } else if (outResult.Value is Enum) { value = outResult.Value.ToString(); } else if (outResult.Value == null) { value = null; } else { //for complex types using (var ms = new MemoryStream()) using (var stream = new BufferedStream(ms)) { Type outResultType = outResult.Value.GetType(); IEnumerable <Type> serviceKnownTypes = _operation .GetServiceKnownTypesHierarchy() .Select(x => x.Type); var serializer = new DataContractSerializer(outResultType, serviceKnownTypes); serializer.WriteObject(ms, outResult.Value); stream.Position = 0; using (var reader = XmlReader.Create(stream)) { reader.MoveToContent(); value = reader.ReadInnerXml(); } } } if (value != null) { writer.WriteRaw(string.Format("<{0}>{1}</{0}>", outResult.Key, value)); } } writer.WriteEndElement(); }
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(); }