• .NET调用外部接口将得到的List数据,并使用XmlSerializer序列化List对象成XML格式


           BidOpeningData.BidSupervisionSoapClient client = new BidOpeningData.BidSupervisionSoapClient();
                Dictionary<string, string> param = new Dictionary<string, string>();
                param.Add(CommonParam.ConnKey, DBConnHelper.GetConnectionKey(DBConnHelper.BusinessData));
                param.Add(CommonParam.AppNo, SystemPlatformEnum.BackStage_Platform);
                param.Add(CommonParam.FunctionNo, ((int)SystemModuleEnum.BackStage_AssistQuery).ToString());
                param.Add(CommonParam.Command, "FindBidOpeningList");
                param.Add("PageIndex", "1");
                param.Add("PageSize", "100000");
                param.Add("BidOpenDateStart", Request.QueryString["BidOpenDateStart"]);//开始时间
                param.Add("BidOpenDateEnd", Request.QueryString["BidOpenDateEnd"]);//结束时间
               
                System.Data.DataSet ds = new System.Data.DataSet("QueryDataSet");
                apiHelper.GetDataTable(param, ref ds, "QueryTable");
                string  queryXmlStr = ds.GetXml();
    
                var aaa = client.GetBidOpeningList(queryXmlStr);
                List<BidOpeningData.BidOpeningInfo> lst = new List<BidOpeningData.BidOpeningInfo>();
                //lst = aaa.ToList();
                //过滤重复数据
                lst = aaa.Distinct().ToList();
                lst = lst.Where((x, i) => lst.FindIndex(z => z.BidSectionDataKey == x.BidSectionDataKey) == i).ToList();
                XmlDocument xd = new XmlDocument();
                using (StringWriter sw = new StringWriter())
                {
                    XmlSerializer xz = new XmlSerializer(lst.GetType());
                    xz.Serialize(sw, lst);
                    xd.LoadXml(sw.ToString());
                }
                //xd.LastChild.OuterXml
    
                param.Clear();
                param.Add(CommonParam.ConnKey, DBConnHelper.GetConnectionKey(DBConnHelper.MaccoData));
                param.Add(CommonParam.AppNo, SystemPlatformEnum.BackStage_Platform);
                param.Add(CommonParam.FunctionNo, "998020");
                param.Add(CommonParam.Command, "DoSaveBidOpeningRecord");
                param.Add("ArrayOfBidOpeningInfo", xd.LastChild.InnerXml.Replace(" xmlns="http://tempuri.org/"",""));
                var result = await apiHelper.HandleData(null, param);//提交信息
                return JsonConvert.DeserializeObject(result).ToString();

    PS:使用XmlSerializer序列化List对象成XML格式

    XmlDocument xd = new XmlDocument();
    using (StringWriter sw = new StringWriter())
    {
        XmlSerializer xz = new XmlSerializer(lst.GetType());//lst为List数据
        xz.Serialize(sw, lst);
        Console.WriteLine(sw.ToString());
        xd.LoadXml(sw.ToString());
    }
  • 相关阅读:
    checkbox 全选与全消
    sql server 关联和一些函数
    checkbox 判断是否选择
    sql 总结
    前台写逻辑
    android应用开发——popupWindow非全屏显示
    整理PostgreSQL数据库占用磁盘空间
    PHP常用的几个函数
    MySQL,PostgreSQL系统表(确认配置是否生效)
    Linux,查看目录大小
  • 原文地址:https://www.cnblogs.com/kongxiaoshuang/p/5976014.html
Copyright © 2020-2023  润新知