예제 #1
0
        /// <summary>
        /// 向远程服务器上传xml文件
        /// </summary>
        /// <param name="host"></param>
        /// <param name="filePath"></param>
        /// <param name="o">将要序列化xml的对象</param>
        /// <returns></returns>
        public static bool RemotePutFile(string host, string filePath, object o)
        {
            HttpClient client = new HttpClient();

            client.Url = host + "/ClientServices/Utilts.ashx";
            client.PostingData.Add("action", "putFile");
            client.PostingData.Add("filePath", filePath);
            client.AttachFile(SerializerUtil.SaveRomoteXml(o), Path.GetFileName(filePath), "file", "text/XML");
            string res     = client.GetString();
            string xmlpath = HttpContext.Current.Server.MapPath(ConfigUtil.GetConfig("ErrorLogPath") + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".xml");
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("服务器返回值", res);
            if (XmlUtil.CreateDocument(xmlpath, "root"))
            {
                XmlUtil.InsertElement(xmlpath, "root", "error", dic, "");
            }

            if (res == "1")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// xml反序列化
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static object LoadRemoteXml(string host, string filePath, System.Type type)
        {
            HttpClient client = new HttpClient();

            client.Url = host + "/" + filePath;
            client.Context.Cookies.Add(new Cookie("4", SecurityUtils.EncryptAES("1"), "/", ConfigUtil.GetConfig("domain")));
            client.Context.Cookies.Add(new Cookie("0", SecurityUtils.EncryptAES("1"), "/", ConfigUtil.GetConfig("domain")));
            client.Context.Cookies.Add(new Cookie("1", SecurityUtils.EncryptAES("1"), "/", ConfigUtil.GetConfig("domain")));
            client.Context.Cookies.Add(new Cookie("2", SecurityUtils.EncryptAES("1"), "/", ConfigUtil.GetConfig("domain")));
            client.Context.Cookies.Add(new Cookie("9", SecurityUtils.EncryptAES("1"), "/", ConfigUtil.GetConfig("domain")));
            client.Context.Cookies.Add(new Cookie("10", SecurityUtils.EncryptAES("1"), "/", ConfigUtil.GetConfig("domain")));
            try
            {
                using (Stream stream = client.GetStream())
                {
                    using (System.IO.StreamReader reader = new System.IO.StreamReader(stream, Encoding.UTF8))
                    {
                        System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(type);
                        try
                        {
                            object obj = xs.Deserialize(reader);
                            reader.Close();
                            return(obj);
                        }
                        catch (Exception e)
                        {
                            reader.Close();
                            return(null);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }
예제 #3
0
 public void getpath()
 {
     xmlpath = DNTUtils.GetMapPath(ConfigUtil.GetConfig("ErrorLogPath") + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".xml");
 }