public string replyContent(string ToUserName, string FromUserName, string Content) { ReplyContent replycontext = new ReplyContent(); replycontext.ToUserName = "******" + ToUserName + "]]>"; replycontext.FromUserName = "******" + FromUserName + "]]>"; replycontext.CreateTime = Util.ConvertDateTimeInt(DateTime.Now); replycontext.MsgType = "<![CDATA[" + FromUserName + "]]>"; replycontext.Content = "<![CDATA[" + Content + "]]>"; //序列化这个对象 string str = ""; XmlSerializer xz = new XmlSerializer(replycontext.GetType()); using (StringWriter sw = new StringWriter()) { XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = false; XmlSerializerNamespaces xns = new XmlSerializerNamespaces(); xns.Add("", ""); xz.Serialize(sw, replycontext, xns); //xz.Serialize(sw, replycontext); str = sw.ToString(); } //str = str.Replace("",""); str = str.Substring(str.IndexOf("<xml>")); str = str.Replace("\r\n", ""); return(str); }