/// <summary> /// Método acionad quando for escreve o contúdo do corpo. /// </summary> /// <param name="writer"></param> protected override void OnWriteBodyContents(System.Xml.XmlDictionaryWriter writer) { writer.WriteStartElement("root"); writer.WriteAttributeString("type", "object"); WriteException(writer, _exception); writer.WriteEndElement(); }
public override void WriteObject(System.Xml.XmlDictionaryWriter writer, object graph) { if (this.info.IsWrapped) { this.serializer.Serialize(writer, graph); } else { System.IO.MemoryStream ms = new System.IO.MemoryStream(); System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings(); settings.OmitXmlDeclaration = true; System.Xml.XmlWriter innerWriter = System.Xml.XmlDictionaryWriter.Create(ms, settings); this.serializer.Serialize(innerWriter, graph); innerWriter.Close(); ms.Position = 0; System.Xml.XmlReader innerReader = System.Xml.XmlDictionaryReader.Create(ms); innerReader.Read(); writer.WriteAttributes(innerReader, false); if ((innerReader.IsEmptyElement == false)) { innerReader.Read(); for ( ; ((innerReader.NodeType == System.Xml.XmlNodeType.EndElement) == false); ) { writer.WriteNode(innerReader, false); } } innerReader.Close(); } }
protected override void OnWriteHeaderContents(System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion) { writer.WriteElementString("SessionID", @"http://schemas.datacontract .org/2004/07/Epicor.Hosting", SessionId.ToString()); writer.WriteElementString("UserID", @"http://schemas.datacontract.or g/2004/07/Epicor.Hosting", EpicorUserId); }
protected override void OnWriteDetailContents(System.Xml.XmlDictionaryWriter writer) { var ser = new XmlSerializer(details.GetType()); ser.Serialize(writer, details); 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); }
/// <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(System.Xml.XmlDictionaryWriter writer) { byte[] bytes = new byte[this.stream.Length]; this.stream.Position = 0; this.stream.Read(bytes, 0, bytes.Length); writer.WriteRaw(this.encoding.GetString(bytes)); }
protected override void OnWriteHeaderContents(System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion) { writer.WriteElementString("Company", @"http://schemas.datacontract.org/2004/07/Epicor.Hosting", Company); writer.WriteElementString("FormatCulture", @"http://schemas.datacontract.org/2004/07/Epicor.Hosting", ""); writer.WriteElementString("Language", @"http://schemas.datacontract.org/2004/07/Epicor.Hosting", ""); writer.WriteElementString("Plant", @"http://schemas.datacontract.org/2004/07/Epicor.Hosting", Plant); writer.WriteElementString("TimezoneOffset", @"http://schemas.datacontract.org/2004/07/Epicor.Hosting", 0.ToString()); }
protected override void OnWriteAddressHeaderContents(System.Xml.XmlDictionaryWriter writer) { // here you do what you want 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(System.Xml.XmlDictionaryWriter writer) { var dynMethod = _message.GetType() .GetMethod("OnWriteBodyContents", BindingFlags.NonPublic | BindingFlags.Instance); if (dynMethod != null) { dynMethod.Invoke(_message, new object[] { writer }); } }
/// <summary> /// 『DataMemberAttribute Class』 /// 使用 [DataContract()] 标记class /// 使用 [DataMember(Name = "ID")] / [DataMember] 标记成员 /// 并且不要求成员访问修饰符为public /// </summary> public static void SerializeContractData <T>(T serializeClass, string filePath) { if (serializeClass != null) { FileStream fs = new FileStream(filePath, FileMode.Create); System.Xml.XmlDictionaryWriter writer = System.Xml.XmlDictionaryWriter.CreateTextWriter(fs); System.Runtime.Serialization.DataContractSerializer ser = new System.Runtime.Serialization.DataContractSerializer(typeof(T)); ser.WriteObject(writer, serializeClass); writer.Close(); fs.Close(); } }
//public override string Name => throw new NotImplementedException(); //public override string Namespace => throw new NotImplementedException(); protected override void OnWriteHeaderContents( System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion) { XmlSerializer serializer = new XmlSerializer(typeof(ModelInterceptor)); StringWriter textWriter = new StringWriter(); //serializer.Serialize(textWriter, _customData); textWriter.Close(); string text = textWriter.ToString(); writer.WriteElementString(CUSTOM_HEADER_NAME, "Key", text.Trim()); }
protected override void OnWriteHeaderContents(System.Xml.XmlDictionaryWriter writer, System.ServiceModel.Channels.MessageVersion messageVersion) { writer.WriteStartElement("wsse", "UsernameToken", Namespace); writer.WriteStartElement("wsse", "Username", Namespace); writer.WriteValue(userName); writer.WriteEndElement(); writer.WriteStartElement("wsse", "Password", Namespace); writer.WriteValue(password); writer.WriteEndElement(); writer.WriteEndElement(); }
protected override void OnWriteStartHeader( System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion) { base.OnWriteStartHeader(writer, messageVersion); // Write your custom XML using the XmlDictionaryClass: //TODO: add the 'param' XML namespace to the writer... //TODO: add the container element with something like this: writer.WriteElementString("SaglikNetParameters", "param", ""); writer.WriteElementString("parameter", "param", "2"); writer.WriteAttributeString("name", "", "islemKodu"); //TODO: complete the rest of the XML ... }
/// <summary> /// Método acionad quando for escreve o contúdo do corpo. /// </summary> /// <param name="writer"></param> protected override void OnWriteBodyContents(System.Xml.XmlDictionaryWriter writer) { writer.WriteStartElement("root"); writer.WriteAttributeString("type", "object"); XElement root = _exMsg.Root; foreach (XElement el in root.Descendants()) { writer.WriteStartElement(el.Name.ToString()); writer.WriteAttributeString("type", "string"); writer.WriteString(el.Value.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); }
public override void WriteObjectContent(System.Xml.XmlDictionaryWriter writer, object graph) { if (graph == null) { writer.WriteAttributeString("nil", "true"); } else { using (MemoryStream ms = new MemoryStream()) { Serializer.Serialize <T>(ms, (T)graph); byte[] buffer = ms.GetBuffer(); writer.WriteBase64(buffer, 0, (int)ms.Length); } } }
private void WriteException(System.Xml.XmlDictionaryWriter writer, Exception exception) { writer.WriteStartElement("type"); writer.WriteAttributeString("type", "string"); writer.WriteString(exception.GetType().Name); writer.WriteEndElement(); writer.WriteStartElement("error"); writer.WriteAttributeString("type", "string"); writer.WriteString(exception.Message); writer.WriteEndElement(); if (exception.InnerException != null) { writer.WriteStartElement("inner"); writer.WriteAttributeString("type", "object"); WriteException(writer, exception.InnerException); writer.WriteEndElement(); } }
/// <summary> /// Write body contents /// </summary> protected override void OnWriteBodyContents(System.Xml.XmlDictionaryWriter writer) { writer.WriteStartDocument(); using (MemoryStream ms = new MemoryStream()) { using (Stream gzs = this.m_compressor.CreateCompressionStream(ms)) { gzs.Write(this.m_data, 0, this.m_data.Length); gzs.Flush(); } writer.WriteStartElement("Binary"); byte[] arr = ms.ToArray(); writer.WriteBase64(arr, 0, arr.Length); writer.WriteEndElement(); } writer.WriteEndDocument(); }
/// <summary> /// Writes the body of an object in the output /// </summary> public override void WriteObjectContent(System.Xml.XmlDictionaryWriter writer, object graph) { if (graph == null) { writer.WriteAttributeString("nil", "true"); } else { using (MemoryStream ms = new MemoryStream()) { using (ProtoWriter protoWriter = new ProtoWriter(ms, model, null)) { model.Serialize(key, graph, protoWriter); } byte[] buffer = ms.GetBuffer(); writer.WriteBase64(buffer, 0, (int)ms.Length); } } }
/// <summary> /// WriteObjectContent is called to serialze the object to writer. Serialze will do the work here. /// </summary> /// <param name="writer"></param> /// <param name="graph"></param> public override void WriteObjectContent(System.Xml.XmlDictionaryWriter writer, object graph) { if (null != graph) { ICollection objectList = graph as ICollection; if (objectList != null) { // handle the list case foreach (object currentObject in objectList) { privateSerializer.Serialize(writer, currentObject); } } else { // handle the scalar case privateSerializer.Serialize(writer, graph); } } }
protected override void OnWriteHeaderContents(System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion) { if (_queryParts != null) { foreach (var part in _queryParts) { writer.WriteStartElement(QueryOptionElementName); writer.WriteAttributeString(QueryNameAttribute, part.QueryOperator); writer.WriteAttributeString(QueryValueAttribute, part.Expression); writer.WriteEndElement(); } } if (_includeTotalCount == true) { writer.WriteStartElement(QueryOptionElementName); writer.WriteAttributeString(QueryNameAttribute, QueryIncludeTotalCountOption); writer.WriteAttributeString(QueryValueAttribute, "true"); writer.WriteEndElement(); } }
public void WriteBodyContents_UnitTest() { System.Xml.XmlDictionaryWriter writer = default(System.Xml.XmlDictionaryWriter); ExecuteMethod( () => { return((DynCon.OSI.VSO.SharedInterfaces.TFS.Client.Channels.ITfsBodyWriter)GetInstance()); }, (instance) => { writer = default(System.Xml.XmlDictionaryWriter); //No Type WriteBodyContents_PreCondition(ref instance, ref writer); }, (instance) => { instance.WriteBodyContents(writer); }, (instance) => { WriteBodyContents_PostValidate(instance, writer); }); }
public void WriteAddressHeaderContents(System.Xml.XmlDictionaryWriter writer) { }
public void WriteStartAddressHeader(System.Xml.XmlDictionaryWriter writer) { }
protected abstract void OnWriteAddressHeaderContents(System.Xml.XmlDictionaryWriter writer);
protected virtual new void OnWriteStartAddressHeader(System.Xml.XmlDictionaryWriter writer) { Contract.Requires(writer != null); }
public override void WriteEndObject(System.Xml.XmlDictionaryWriter writer) { }
public override void WriteStartObject(System.Xml.XmlDictionaryWriter writer, object graph) { }
public override void WriteObjectContent(System.Xml.XmlDictionaryWriter writer, object graph) { }
public abstract void WriteStartObject(System.Xml.XmlDictionaryWriter writer, object graph);
public abstract void WriteObjectContent(System.Xml.XmlDictionaryWriter writer, object graph);