C# Linq方式生成SAP对接的XML格式内容(一般处理程序 ashx )

2021-05-23 03:28

阅读:586

标签:opened   RoCE   end   处理   mon   oid   new   man   数据   

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();//@"";
            return strdoc + xdoc.ToString();

        }
View Code

生成结果格式:

技术图片技术图片
"1.0" encoding="UTF-8"?>

"http://schemas.xmlsoap.org/soap/envelope/">


"http://www.db.com">

DB_XZQYSJTB{"MANTD":"0000","MANTR":"0000"}
View Code

访问方法:

 public void ProcessRequest(HttpContext context)
        {

            int rowcount = (int)context.Request.InputStream.Length;
            byte[] buff = new byte[rowcount];
            context.Request.InputStream.Read(buff, 0, rowcount);
            string text = System.Text.Encoding.UTF8.GetString(buff);
            Log4.WriteLog("Handler非标接收数据:" + text ?? "");
/***********************************************************/
            Dictionarystring, object> dic = new Dictionarystring, object>();
            dic.Add("AAA", "0000");
            dic.Add("BBB", "0000");
            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();         

        }

 

C# Linq方式生成SAP对接的XML格式内容(一般处理程序 ashx )

标签:opened   RoCE   end   处理   mon   oid   new   man   数据   

原文地址:https://www.cnblogs.com/lzsin/p/11163722.html


评论


亲,登录后才可以留言!