Linq生成XML的方法:

 string CreateXML(string strkey, string strDATAJSON)
{ XDeclaration dec = new XDeclaration("1.0", "UTF-8", null);
XDocument xdoc = new XDocument();
XNamespace saop = "http://schemas.xmlsoap.org/soap/envelope/";
XNamespace ns0 = "http://www.db.com";
XElement root = new XElement(saop + "Envelope",
new XAttribute(XNamespace.Xmlns + "soap", "http://schemas.xmlsoap.org/soap/envelope/"),
new XElement(saop + "Body",
new XElement(ns0 + "MT_COMMON_RET",
new XAttribute(XNamespace.Xmlns + "ns0", "http://www.db.com"),
new XElement("KEY", strkey),
new XElement("DATAJSON_RET", strDATAJSON))) );
xdoc.Add(root);
string strdoc = dec.ToString();//@"<?xml version=""1.0"" encoding=""utf-8""?>";
return strdoc + xdoc.ToString(); }

生成结果格式:

<?xml version="1.0" encoding="UTF-8"?>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

<soap:Body>

<ns0:MT_COMMON_RET xmlns:ns0="http://www.db.com">

<KEY>DB_XZQYSJTB</KEY>

<DATAJSON_RET>{"MANTD":"","MANTR":""}</DATAJSON_RET>

</ns0:MT_COMMON_RET>

</soap:Body>

</soap:Envelope>

访问方法:

 public void ProcessRequest(HttpContext context)
{ int rowcount = (int)context.Request.InputStream.Length;
byte[] buff = new byte[rowcount];
context.Request.InputStream.Read(buff, , rowcount);
string text = System.Text.Encoding.UTF8.GetString(buff);
Log4.WriteLog("Handler非标接收数据:" + text ?? "");
/***********************************************************/
Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("AAA", "");
dic.Add("BBB", "");
string strDATAJSON = Common.Tools.ConvertToJsonStr(dic);
string strxml = CreateXML("KEY值", strDATAJSON);
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.AddHeader("Content-Length", strxml.Length.ToString());
context.Response.ContentType = "text/xml";
context.Response.Write(strxml);
context.Response.Flush();
context.Response.End(); }

最新文章

  1. ASP.NET MVC 3 技术(九) 301永久重定向不带www域名到带www的域名
  2. 【译】java.lang.ThreadLocal
  3. 3、eclipse和maven环境安装以及HDFS读写的demo
  4. UOJ30——【CF Round #278】Tourists
  5. Servlet,GenericServlet和HttpServlet的继承关系
  6. UVa 11210 (DFS) Chinese Mahjong
  7. [Arduino] 外部中断
  8. K - 计算球体积
  9. js深入研究之类定义与使用
  10. css学习笔记二
  11. 提高你的Java代码质量吧:使用构造函数协助描述枚举项
  12. Spring+SpringMVC+MyBatis+easyUI整合基础篇(十)SVN搭建
  13. Android在listview添加checkbox实现单选多选操作问题
  14. 利用Eclipse中的Maven构建Web项目报错(一)
  15. Python-读文件
  16. cf1136E. Nastya Hasn&#39;t Written a Legend(二分 线段树)
  17. 更好用的excel国际化多语言导出
  18. 雷林鹏分享:使用 CSS 显示 XML
  19. spring事务——try{...}catch{...}中事务不回滚的几种处理方式
  20. poj 3667 线段树

热门文章

  1. JXJJOI2018_三题
  2. 【转载】[基础知识]【网络编程】TCP/IP
  3. 剑指CopyOnWriteArrayList
  4. Daily Practice 2016-09-20
  5. 直接拿来用,10个PHP代码片段(收藏)
  6. Jquery Ajax Post Json
  7. python基础-基本概念
  8. 达拉草201771010105《面向对象程序设计(java)》第十四周学习总结
  9. Javascript学习笔记-基本概念-操作符
  10. python数组和字符串互相转换