将标头添加到WCF消息

时间:2014-11-21 23:37:39

标签: xml wcf c#-4.0 xml-serialization xmldocument

如何在此消息中添加标题并获取所有xml文档?

  private Message GetRootMessage()
  {
      var stream = new MemoryStream();
      XmlDictionaryWriter writer =  XmlDictionaryWriter.CreateTextWriter(stream);
      writer.WriteStartDocument();
      writer.WriteStartElement("Body");
      writer.WriteAttributeString("abc", "2012-04-17t10:00:00Z");
      writer.WriteAttributeString("abd", "CA");
      writer.WriteAttributeString("bid", "35353");

      writer.WriteEndElement();   
      writer.WriteEndDocument();
      writer.Flush();
      stream.Position = 0;

      XmlDictionaryReader reader = 
          XmlDictionaryReader.CreateTextReader(
          stream, XmlDictionaryReaderQuotas.Max);
      return Message.CreateMessage(
          MessageVersion.None, "", reader);
  }

1 个答案:

答案 0 :(得分:0)

IDispatchMessageInspector你是这里的朋友,看看this post的想法。