概要:将A项目中的Xml文件通过http推送至B项目,以保证B项目中的Xml与A项目的Xml同步
此文档包括两主要点:Xml操作及http传输与响应
1.在项目A中主要进行生成最新的Xml文件,然后通过http传送到B项目
生成最新的Xml文件(带上版本号):附上Xml文件生成代码
/// <summary> /// 生成最新的Xml地图文件 /// </summary> private void BulidMapXml() { string XmlUrl = Server.MapPath("~/") + WsmsXmlUrl;//Xml文件的物理地址 //实现监控点的权限控制 string monitorySitePowers = CommonUtility.GetMonitorySitePower();//用户的监控点权限 //获取区域及监控点信息 DataTable dtArea = new DataTable(); dtArea = iDictionaryAdminService.LoadAllArea(); DataTable dtMonitorySite = new DataTable(); dtMonitorySite = iMonitorySiteAdminService.GetAllMonitorySiteHaveArchivesID(monitorySitePowers);//获取全部监控点信息 //打开与修改Xml文档 XmlDocument XmlDoc = new XmlDocument(); XmlDoc.Load(XmlUrl);//加载本地的Xml文件 XmlNode root = XmlDoc.SelectSingleNode("Items");//选择第一个Items的XML节点 XmlElement rootEle = (XmlElement)root;//将节点转为元素 int Version = int.Parse(rootEle.GetAttribute("Version").ToString());//获取此Xml文件的版本号 int NewVersion = Version + 1;//对版本号进行加1标志 root.RemoveAll();//移除root所有节点的子节点及属性 rootEle.SetAttribute("Version", NewVersion.ToString());//设置此Xml文件的版本号 #region 具体实现怎么添加Xml文件主内容(根据实际情况) if (dtArea.Rows.Count == 0) { if (dtMonitorySite != null) { DataView dv = new DataView(dtMonitorySite); dv.RowFilter = " SubrangeID Is Null ";//查询条件,所属区域 foreach (DataRowView drv in dv) { XmlElement xeSub = XmlDoc.CreateElement("MonitorySite");//创建MonitorySite标志的元素 xeSub.SetAttribute("CommunicationCardno", drv["CommunicationCardno"].ToString()); xeSub.SetAttribute("SiteName", drv["SiteName"].ToString()); xeSub.SetAttribute("FullAddress", drv["FullAddress"].ToString()); xeSub.SetAttribute("ArchivesID", drv["ArchivesID"].ToString()); xeSub.SetAttribute("Longitude", drv["Longitude"].ToString()); xeSub.SetAttribute("Latitude", drv["Latitude"].ToString()); rootEle.AppendChild(xeSub);//将MonitorySite标志的元素添加到rootEle节点下 } } } else { DataView dvTree = new DataView(dtArea); foreach (DataRowView row in dvTree) { XmlElement xe = XmlDoc.CreateElement("Item");//创建MonitorySite标志的元素 xe.SetAttribute("ID", row["ID"].ToString());//设置Item元素的属性 xe.SetAttribute("AreaName", row["AreaName"].ToString());//设置Item元素的属性 DataView dv = new DataView(dtMonitorySite); dv.RowFilter = " SubrangeID = '" + row["ID"].ToString() + "'";//查询条件,所属区域(过滤) foreach (DataRowView drv in dv) { XmlElement xeSub = XmlDoc.CreateElement("MonitorySite"); xeSub.SetAttribute("CommunicationCardno", drv["CommunicationCardno"].ToString()); xeSub.SetAttribute("SiteName", drv["SiteName"].ToString()); xeSub.SetAttribute("FullAddress", drv["FullAddress"].ToString()); xeSub.SetAttribute("ArchivesID", drv["ArchivesID"].ToString()); xeSub.SetAttribute("Longitude", drv["Longitude"].ToString()); xeSub.SetAttribute("Latitude", drv["Latitude"].ToString()); rootEle.AppendChild(xeSub); } rootEle.AppendChild(xe);//将Item元素添加到rootEle节点下 } DataView dvMonitorySite = new DataView(dtMonitorySite); dvMonitorySite.RowFilter = " SubrangeID Is Null ";//查询条件,所属区域 foreach (DataRowView drv in dvMonitorySite) { XmlElement xeSub = XmlDoc.CreateElement("MonitorySite"); xeSub.SetAttribute("CommunicationCardno", drv["CommunicationCardno"].ToString()); xeSub.SetAttribute("SiteName", drv["SiteName"].ToString()); xeSub.SetAttribute("FullAddress", drv["FullAddress"].ToString()); xeSub.SetAttribute("ArchivesID", drv["ArchivesID"].ToString()); xeSub.SetAttribute("Longitude", drv["Longitude"].ToString()); xeSub.SetAttribute("Latitude", drv["Latitude"].ToString()); rootEle.AppendChild(xeSub);//将Item元素添加到rootEle节点下 } } #endregion XmlDoc.Save(XmlUrl);//将XmlDoc文件保存到XmlUrl }
附上生成的Xml文件:
<?xml version="1.0" encoding="utf-8"?> <Items Version="27"> <Item ID="1" AreaName="鼓台区" /> <MonitorySite CommunicationCardno="15980687527" SiteName="省立医院(东街)" FullAddress="鼓楼区东街" ArchivesID="1001000225" Longitude="119.1824" Latitude="26.0674" /> <MonitorySite CommunicationCardno="13665047625" SiteName="省外贸中心酒店" FullAddress="古楼区五四路73号" ArchivesID="1001000426" Longitude="119.1807" Latitude="26.0542" /> <MonitorySite CommunicationCardno="13665047105" SiteName="国际民航广场阿波罗大酒店公寓" FullAddress="台江区浦尾路" ArchivesID="1001070907" Longitude="119.1820" Latitude="26.0370" /> <MonitorySite CommunicationCardno="15959028651" SiteName="省西湖宾馆" FullAddress="鼓楼区湖滨路158号(远传)" ArchivesID="1001080182" Longitude="119.1716" Latitude="26.0554" /> <MonitorySite CommunicationCardno="15959027607" SiteName="南京军区福州总医院" FullAddress="鼓楼区西环北路156号*10" ArchivesID="1001090213" Longitude="119.1636" Latitude="26.0533" /> <MonitorySite CommunicationCardno="15980698957" SiteName="福州大学宿舍" FullAddress="鼓楼区工业路*10" ArchivesID="1001110039" Longitude="119.1624" Latitude="26.0423" /> <MonitorySite CommunicationCardno="15080018275" SiteName="青岛啤酒(福州)有限公司" FullAddress="台江区工业路*10" ArchivesID="1001110070" Longitude="119.1620" Latitude="26.0440" /> <MonitorySite CommunicationCardno="15980681872" SiteName="福州大学西区" FullAddress="鼓楼区杨桥路" ArchivesID="1001120461" Longitude="119.1550" Latitude="26.0436" /> <MonitorySite CommunicationCardno="13665047427" SiteName="省妇幼保健院" FullAddress="鼓楼道山路18号" ArchivesID="1001130237" Longitude="119.1744" Latitude="26.0454" /> <MonitorySite CommunicationCardno="15080017811" SiteName="福州梅峰宾馆生活区" FullAddress="鼓楼区光铜路2号" ArchivesID="1001140440" Longitude="119.0944" Latitude="26.0337" /> <MonitorySite CommunicationCardno="15959026309" SiteName="福州大学" FullAddress="鼓楼区杨桥西路65" ArchivesID="1001160396" Longitude="119.1550" Latitude="26.0436" /> <MonitorySite CommunicationCardno="13665047589" SiteName="医学院附属第一医院" FullAddress="白马路西洋村医学院附属第一医院" ArchivesID="1001200383" Longitude="119.1971" Latitude="26.0323" /> <MonitorySite CommunicationCardno="15959046728" SiteName="福州教育中心基地" FullAddress="台江区群众路196号" ArchivesID="1001200436" Longitude="119.1971" Latitude="26.0323" /> <MonitorySite CommunicationCardno="15880090872" SiteName="鼓楼区人民政府办公室" FullAddress="鼓楼区津泰路98号" ArchivesID="1001210260" Longitude="119.1758" Latitude="26.0506" /> <MonitorySite CommunicationCardno="15980694538" SiteName="省医科大学" FullAddress="鼓楼区交通路88号" ArchivesID="1001230180" Longitude="119.1731" Latitude="26.0425" /> <MonitorySite CommunicationCardno="13665047697" SiteName="福州正福房地产开发有限公司" FullAddress="鼓楼区五一中路18号" ArchivesID="1010001511" Longitude="119.1845" Latitude="26.0417" /> <MonitorySite CommunicationCardno="15080018639" SiteName="市一医院(采集)" FullAddress="台江区大道" ArchivesID="1108070192" Longitude="119.1846" Latitude="26.0335" /> <MonitorySite CommunicationCardno="15080018223" SiteName="市水批发二期工程" FullAddress="东宾路36号名成食品公司门前" ArchivesID="1108120813" Longitude="119.1971" Latitude="26.0323" /> <MonitorySite CommunicationCardno="15060075531" SiteName="宝龙广场" FullAddress="宝龙广场" ArchivesID="1123004643" Longitude="119.1971" Latitude="26.0323" /> <Item ID="3" AreaName="仓山区" /> <MonitorySite CommunicationCardno="13805014869" SiteName="莲花山风景区斗顶村老人会馆" FullAddress="福飞路森林公园对面莲花山风景区斗顶村老人会馆" ArchivesID="00800029" Longitude="119.1819" Latitude="26.0853" /> <MonitorySite CommunicationCardno="13599421790" SiteName="祥谦镇江中村塔礁老人会" FullAddress="祥谦镇江中村塔礁老人会" ArchivesID="1123013850" Longitude="119.2134" Latitude="25.5657" /> <MonitorySite CommunicationCardno="15205005834" SiteName="福州大酒家" FullAddress="古楼区西湖交际处边(远传)" ArchivesID="1001150043" Longitude="119.1709" Latitude="26.0558" /> <MonitorySite CommunicationCardno="15959141048" SiteName="省电二建公司南院宿舍" FullAddress="晋安区茶园路48号" ArchivesID="1001000124" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="13489149623" SiteName="温泉澡堂" FullAddress="鼓楼区温泉路" ArchivesID="1001000159" Longitude="119.1816" Latitude="26.0536" /> <MonitorySite CommunicationCardno="15259195514" SiteName="福建嘉达纺织股份有限公司" FullAddress="鼓楼区福飞路143号*10" ArchivesID="1001000465" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15259195814" SiteName="省体工队" FullAddress="古楼区北门龙腰" ArchivesID="1001000474" Longitude="119.1736" Latitude="26.0700" /> <MonitorySite CommunicationCardno="15205046414" SiteName="福州耀隆化工集团公司" FullAddress="晋安区化工路" ArchivesID="1001010345" Longitude="119.3377" Latitude="26.0943" /> <MonitorySite CommunicationCardno="13489149674" SiteName="市城乡建设发展总公司祥板小区" FullAddress="台江区工业西路325号" ArchivesID="1001020704" Longitude="119.1638" Latitude="26.0403" /> <MonitorySite CommunicationCardno="15005976124" SiteName="福州邦辉大酒店" FullAddress="鼓楼区温泉支路过洋档8号" ArchivesID="1001030565" Longitude="119.1817" Latitude="26.0537" /> <MonitorySite CommunicationCardno="13489022205" SiteName="佳洲房产“世纪明珠”多层住宅" FullAddress="晋安区晋安北路" ArchivesID="1001030753" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15005976314" SiteName="福州东汤物业管理有限公司" FullAddress="古楼区温泉东汤村" ArchivesID="1001050416" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15060427340" SiteName="市统建办湖前小区" FullAddress="鼓楼区白水塘路106号(福飞射击场对面)" ArchivesID="1001060356" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15005976564" SiteName="福建省游泳跳水比赛站" FullAddress="古楼区五四北路310号(单放游泳馆保安处)" ArchivesID="1001060702" Longitude="119.1802" Latitude="26.0701" /> <MonitorySite CommunicationCardno="15205046934" SiteName="医科大学附属第一医院门诊综合楼" FullAddress="台江区茶中路20" ArchivesID="1001070876" Longitude="119.1752" Latitude="26.0423" /> <MonitorySite CommunicationCardno="13489149675" SiteName="国际民航广场“阿菠罗大酒店”宾馆" FullAddress="台江区浦尾路" ArchivesID="1001070909" Longitude="119.1823" Latitude="26.0411" /> <MonitorySite CommunicationCardno="15980685092" SiteName="昌融房产锦江馨园学生公寓" FullAddress="仓山区建新镇劳光村上店路89号" ArchivesID="1001080987" Longitude="119.1428" Latitude="26.0483" /> <MonitorySite CommunicationCardno="13860661579" SiteName="福州空军医院" FullAddress="仓山区洪塘妙峰山" ArchivesID="1001100338" Longitude="119.1437" Latitude="26.0443" /> <MonitorySite CommunicationCardno="15259195824" SiteName="福州闽长物业管理有限公司" FullAddress="鼓楼区杨桥东路19号住宅楼" ArchivesID="1001120641" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="13489199424" SiteName="聚春园菜馆" FullAddress="古街区东街2号" ArchivesID="1001130124" Longitude="119.0742" Latitude="26.0522" /> <MonitorySite CommunicationCardno="15259195784" SiteName="中国人民解放军73833部队" FullAddress="鼓楼区梅峰路6号" ArchivesID="1001140412" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15259195834" SiteName="福州名城物业管理有限公司" FullAddress="晋安区福马路168号*10大名城" ArchivesID="1001140913" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="13509324214" SiteName="省水产厅" FullAddress="鼓楼区冶山路26号" ArchivesID="1001150029" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15280444305" SiteName="福州高意通讯有限公司" FullAddress="晋安区福兴路与福发路交叉路" ArchivesID="1001150662" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15005976304" SiteName="福州大学宿舍40楼" FullAddress="鼓楼区祭酒岭" ArchivesID="1001160398" Longitude="119.1554" Latitude="26.0406" /> <MonitorySite CommunicationCardno="15060428546" SiteName="省教育学院" FullAddress="古楼区梦山巷73号" ArchivesID="1001170483" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15259195774" SiteName="福州大饭店有限公司" FullAddress="鼓楼区817中路103号" ArchivesID="1001180042" Longitude="119.1758" Latitude="26.0435" /> <MonitorySite CommunicationCardno="13489199481" SiteName="软件元科技开发基地" FullAddress="古楼区铜盘马鞍软件大道29号*10" ArchivesID="1001210609" Longitude="119.1603" Latitude="26.0655" /> <MonitorySite CommunicationCardno="15259195574" SiteName="紫阳信用社紫阳村(白宫大酒店)" FullAddress="晋安区福马路53号" ArchivesID="1001220322" Longitude="119.1856" Latitude="26.0447" /> <MonitorySite CommunicationCardno="15259195674" SiteName="福州第三针织厂" FullAddress="晋安区连江中路112号(新116号)" ArchivesID="1001230213" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15259195764" SiteName="五一建设总指挥部" FullAddress="晋安区茶园小区五四民兵路北侧(TJB)" ArchivesID="1003000008" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15005976174" SiteName="福州香格里拉酒店有限公司" FullAddress="鼓楼区市新权南9号" ArchivesID="1010003035" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15259195624" SiteName="福建东百元洪购物广场有限公司" FullAddress="福建省福州市台江区台江路95号二层" ArchivesID="1108060895" Longitude="119.1839" Latitude="26.032" /> <MonitorySite CommunicationCardno="13489146374" SiteName="福州彤辉物业有限公司" FullAddress="台江区达江路三号" ArchivesID="1108070803" Longitude="119.0219" Latitude="26.3019" /> <MonitorySite CommunicationCardno="15080018085" SiteName="福州市仓山区城门镇农业服务中心" FullAddress="福州仓山区城门镇" ArchivesID="1108110166" Longitude="119.2117" Latitude="26.0001" /> <MonitorySite CommunicationCardno="13665047089" SiteName="福建三丰鞋业有限公司" FullAddress="仓山区城门村排下洋" ArchivesID="1108110168" Longitude="119.2108" Latitude="26.0006" /> <MonitorySite CommunicationCardno="15980673595" SiteName="祥宇物业梅花园杏花园" FullAddress="仓山南台新苑"杏花园"2号楼" ArchivesID="1108141005" Longitude="119.1025" Latitude="26.0118" /> <MonitorySite CommunicationCardno="15059189134" SiteName="福建结核病防治院" FullAddress="仓山上渡湖边2号" ArchivesID="1108151037" Longitude="119.1725" Latitude="26.0141" /> <MonitorySite CommunicationCardno="15205046214" SiteName="福建警官学院" FullAddress="仓山区首山路59号" ArchivesID="1108161040" Longitude="119.1839" Latitude="26.0147" /> <MonitorySite CommunicationCardno="15259195734" SiteName="台福(福州)有限公司" FullAddress="台江区鳌峰路67号" ArchivesID="1108170657" Longitude="119.1234" Latitude="25.1456" /> <MonitorySite CommunicationCardno="15959027015" SiteName="福州第二医院" FullAddress="仓山区观海菜园小巷" ArchivesID="1108190889" Longitude="119.0843" Latitude="26.1033" /> <MonitorySite CommunicationCardno="15205046574" SiteName="市房地产经营公司金山生活东区" FullAddress="仓山区金山生活东区金榕路" ArchivesID="1108211185" Longitude="119.1542" Latitude="26.0314" /> <MonitorySite CommunicationCardno="15259195744" SiteName="省军区后勤万里农场" FullAddress="仓山区施埔路58号" ArchivesID="1108220450" Longitude="119.1822" Latitude="26.0158" /> <MonitorySite CommunicationCardno="13506991596" SiteName="儿童发展职业学院" FullAddress="仓山区长安路89号" ArchivesID="1108220453" Longitude="119.0830" Latitude="26.0112" /> <MonitorySite CommunicationCardno="15080017939" SiteName="福建师大01号" FullAddress="仓山区上山路长安山(*10表)" ArchivesID="1108250250" Longitude="119.1616" Latitude="26.0225" /> <MonitorySite CommunicationCardno="13559111094" SiteName="省福汽华泰服务有限公司" FullAddress="古楼区五四华林路214号" ArchivesID="1001000108" Longitude="119.1813" Latitude="26.0623" /> <MonitorySite CommunicationCardno="13559111714" SiteName="融侨房产节滨东路测流表" FullAddress="仓山区融侨房产节滨东路0+045" ArchivesID="1122000654" Longitude="119.1621" Latitude="26.0257" /> <MonitorySite CommunicationCardno="15080018279" SiteName="福建腾新食品股份有限公司" FullAddress="仓山区阵新路(建新北路)" ArchivesID="1122002760" Longitude="119.0844" Latitude="26.0185" /> <MonitorySite CommunicationCardno="15980635792" SiteName="建新镇江边村委会" FullAddress="仓山区仓山浦上工业区金浦路江边村" ArchivesID="1122003003" Longitude="119.1535" Latitude="26.0119" /> <MonitorySite CommunicationCardno="13506996172" SiteName="福州汇合科技有限公司" FullAddress="福建仓山区金山工业区福湾片鼓楼园1号" ArchivesID="1123000542" Longitude="119.0951" Latitude="26.0010" /> <MonitorySite CommunicationCardno="15205046474" SiteName="福州奋安铝业有限公司" FullAddress="仓山区金山工业区建新北路142号" ArchivesID="1123000661" Longitude="119.2475" Latitude="26.0594" /> <MonitorySite CommunicationCardno="13599421793" SiteName="福建郑棣电子有限公司" FullAddress="仓山盖山投资区高旺路6号" ArchivesID="1123000845" Longitude="119.1212" Latitude="26.0043" /> <MonitorySite CommunicationCardno="13599421786" SiteName="福州新榕建设中心(会展中心)" FullAddress="仓山区城门镇潘墩村浦下洲林浦洲" ArchivesID="1123012802" Longitude="119.1840" Latitude="26.0558" /> <MonitorySite CommunicationCardno="13055270677" SiteName="海峡国际会展中心西区" FullAddress="海峡国际会展中心西区" ArchivesID="1846" Longitude="119.1235" Latitude="25.1456" /> <MonitorySite CommunicationCardno="13489022210" SiteName="福建省福州屏东中学游泳馆" FullAddress="鼓楼区屏东路39号" ArchivesID="1001030669" Longitude="119.175" Latitude="26.0606" /> <MonitorySite CommunicationCardno="13509324439" SiteName="福建工程学校" FullAddress="福州晋安区南门口" ArchivesID="1001020596" Longitude="119.2143" Latitude="26.0531" /> <MonitorySite CommunicationCardno="15060433390" SiteName="省测办" FullAddress="古楼区温泉路2号" ArchivesID="1001000555" Longitude="119.1821" Latitude="26.0527" /> <MonitorySite CommunicationCardno="15960139844" SiteName="螺洲镇三期供水(*10测流表)0+628" FullAddress="仓山区城门螺洲镇0+628" ArchivesID="1123000334" Longitude="119.2047" Latitude="25.5921" /> <MonitorySite CommunicationCardno="13489149413" SiteName="金源国际大饭店有限公司金都饭店" FullAddress="古楼区树汤路与公园路交叉口" ArchivesID="1001190658" Longitude="119.1817" Latitude="26.0609" /> <MonitorySite CommunicationCardno="13763866431" SiteName="海峡国际会展中心东区" FullAddress="南江滨东路" ArchivesID="6431" Longitude="119.2146" Latitude="26.0136" /> <MonitorySite CommunicationCardno="15005975554" SiteName="福建省新闻出版务业管理中心" FullAddress="古楼区得贵巷59号" ArchivesID="1001000005" Longitude="119.1830" Latitude="26.0512" /> <MonitorySite CommunicationCardno="15005976145" SiteName="洪立金代表" FullAddress="晋安区前屿" ArchivesID="1001200278" Longitude="119.2032" Latitude="26.043" /> <MonitorySite CommunicationCardno="15005976424" SiteName="金山桔园一期(监控表)" FullAddress="仓山区金山林洲路A2#楼洗测" ArchivesID="76424" Longitude="119.1416" Latitude="26.0256" /> <MonitorySite CommunicationCardno="15059189241" SiteName="福建华科光电有限公司古山投资区" FullAddress="晋安区福马路投资区管委会边" ArchivesID="89241" Longitude="119.2133" Latitude="26.0434" /> <MonitorySite CommunicationCardno="15259195604" SiteName="温泉大饭店" FullAddress="古楼区五四路218号(单放温莎俱乐城边打卡处)" ArchivesID="1001000302" Longitude="119.1804" Latitude="26.0604" /> <MonitorySite CommunicationCardno="15259195614" SiteName="螺洲镇三期供水(*10测流表)" FullAddress="仓山区城门螺洲镇0+608" ArchivesID="1123000333" Longitude="119.2047" Latitude="25.5922" /> <MonitorySite CommunicationCardno="15259195634" SiteName="福建医大附属协和医院" FullAddress="古楼区新村花园口" ArchivesID="1001180587" Longitude="119.1757" Latitude="26.045" /> <MonitorySite CommunicationCardno="15259195644" SiteName="中国人民解放军61716部队" FullAddress="福州市鼓楼区梅峰路3号" ArchivesID="1013013876" Longitude="119.1506" Latitude="26.0536" /> <MonitorySite CommunicationCardno="15259195724" SiteName="福建实达物业有限公司(温泉小区A座)" FullAddress="古楼区树汤路17号温泉小区A座" ArchivesID="1001050682" Longitude="119.1818" Latitude="26.0612" /> <MonitorySite CommunicationCardno="15259195794" SiteName="君临东城监控表" FullAddress="晋安区浦乾路16号26#东侧(君临东城)" ArchivesID="1010005462" Longitude="119.2057" Latitude="26.0417" /> <Item ID="4" AreaName="马尾区" /> <Item ID="5" AreaName="晋安区" /> <MonitorySite CommunicationCardno="15980691732" SiteName="福建省东南电化股份有限公司" FullAddress="晋安区连江路二氮车间" ArchivesID="1001000041" Longitude="119.1933" Latitude="26.0542" /> <MonitorySite CommunicationCardno="15080017896" SiteName="横屿村" FullAddress="晋安区横屿电影院" ArchivesID="1001000057" Longitude="119.2058" Latitude="26.0532" /> <MonitorySite CommunicationCardno="15080018697" SiteName="福建三木集团三木花园" FullAddress="晋安区国货东段*10" ArchivesID="1001130593" Longitude="119.1971" Latitude="26.0323" /> <MonitorySite CommunicationCardno="13665047276" SiteName="福州永同昌地产文华小区住宅" FullAddress="晋安区长春后路18号(前横路)" ArchivesID="1001130707" Longitude="119.1217" Latitude="26.0228" /> <MonitorySite CommunicationCardno="13665047306" SiteName="福建福华纺织印染有限公司" FullAddress="工业路10号" ArchivesID="1001160509" Longitude="119.1249" Latitude="26.0228" /> <MonitorySite CommunicationCardno="15080017851" SiteName="顺大运动用品有限公司" FullAddress="晋安区鼓山福兴开发区通樟林村口" ArchivesID="1001160514" Longitude="119.2137" Latitude="26.0426" /> <MonitorySite CommunicationCardno="15980676527" SiteName="樟林村" FullAddress="晋安区福马樟林村" ArchivesID="1001160540" Longitude="119.2147" Latitude="26.0417" /> <MonitorySite CommunicationCardno="15980698375" SiteName="远中大队" FullAddress="晋安区远洋水站边" ArchivesID="1001160553" Longitude="119.2116" Latitude="26.0361" /> <MonitorySite CommunicationCardno="15980695691" SiteName="福建清禄鞋业有限公司" FullAddress="晋安区福马路福兴投资区远样村0号(远传)" ArchivesID="1001160596" Longitude="119.2137" Latitude="26.0356" /> <MonitorySite CommunicationCardno="15959027931" SiteName="福州大同纤维纺织有限公司工厂" FullAddress="晋安区鼓山镇福兴投资区" ArchivesID="1001160687" Longitude="119.2126" Latitude="26.0427" /> <MonitorySite CommunicationCardno="15980435322" SiteName="清禄鞋业鼓山厂" FullAddress="晋安区福马路远洋村(远传)" ArchivesID="1001170625" Longitude="119.2139" Latitude="26.0439" /> <MonitorySite CommunicationCardno="13665047749" SiteName="省肿瘤医院" FullAddress="晋安区福马路东池" ArchivesID="1001200181" Longitude="119.1975" Latitude="26.0439" /> <MonitorySite CommunicationCardno="13509327465" SiteName="杨亭村" FullAddress="新店镇杨亭村" ArchivesID="7465" Longitude="119.1840" Latitude="26.0558" /> </Items>
发送消息到B服务器:
/// <summary> /// 发送消息到自己的GoogleMap服务器(HttpWebRequest形式) /// </summary> private void SendToGoogleMap() { string strPostUrl = PostUrl + "?Action=abc";//要发送至的地址及参数 StreamReader Reader = null; try { HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(strPostUrl);//通过向StrPostUrl请求发送 HttpWebResponse myResponse = (HttpWebResponse)Request.GetResponse();//通过请求得到的响应 Stream stream = myResponse.GetResponseStream(); Reader = new StreamReader(stream); } catch (Exception) { MessageBox.Show(this, "出错!"); } string StrFalg = null; if (Reader != null) { StrFalg = Reader.ReadToEnd(); } if (StrFalg == "Ok")//此根据B项目发回来的消息而定义,你也可以定义成其他东东 { MessageBox.Show("同步成功!"); } else { MessageBox.Show("同步失败!"); } }
2.B项目接收,同步Xml文件并响应消息
注:如果要发回响应消息,最好用.ashx结尾的一般处理程序。如果不用直接用.aspx页面就可以了
.aspx页面的操作
private static string WsmsXmlUrl = ConfigurationManager.AppSettings["WsmsXmlUrl"]; private static string MapXmlUrl = "Xml/MonitorySiteInfo.xml"; protected void Page_Load(object sender, EventArgs e) { string Action = Request.QueryString["Action"].ToString();//获取传递过来的参数 if (Action != null && Action != string.Empty) { GetSaveXml(); } } /// <summary> /// 获取异地Xml文件,并保存在本地中 /// </summary> private void GetSaveXml() { XmlDocument WsmsXmlDoc = new XmlDocument(); XmlDocument MapXmlDoc = new XmlDocument(); WsmsXmlDoc.Load(WsmsXmlUrl); MapXmlDoc.Load(Server.MapPath("~/") + MapXmlUrl); XmlNode WsmsNode = WsmsXmlDoc.SelectSingleNode("Items"); XmlNode MapNode = MapXmlDoc.SelectSingleNode("Items"); XmlElement WsmsElem = (XmlElement)WsmsNode; XmlElement MapElem = (XmlElement)MapNode; //Label1.Text = WsmsElem.GetAttribute("Version").ToString(); int WsmsVersion = int.Parse(WsmsElem.GetAttribute("Version").ToString()); int MapVersion = int.Parse(MapElem.GetAttribute("Version").ToString()); if (WsmsVersion > MapVersion)//对比版本号,如果是最新的 { WsmsXmlDoc.Save(Server.MapPath("~/") + MapXmlUrl);//将异地的WsmsXmlDoc保存到Server.MapPath("~/") + MapXmlUrl文件中 } }
.ashx的操作
public void ProcessRequest (HttpContext context) { context.Response.Charset = "UTF-8"; context.Response.ContentType = "text/plain"; string Action = context.Request.QueryString["Action"].ToString(); //操作 if (Action != string.empry && Action != null) { GetSaveXml(); context.Response.Write("Ok");//些Ok可以改为其他东西 } } /// <summary> /// 获取异地Xml文件,并保存在本地中 /// </summary> private void GetSaveXml() { XmlDocument WsmsXmlDoc = new XmlDocument(); XmlDocument MapXmlDoc = new XmlDocument(); WsmsXmlDoc.Load(WsmsXmlUrl); MapXmlDoc.Load(Server.MapPath("~/") + MapXmlUrl); XmlNode WsmsNode = WsmsXmlDoc.SelectSingleNode("Items"); XmlNode MapNode = MapXmlDoc.SelectSingleNode("Items"); XmlElement WsmsElem = (XmlElement)WsmsNode; XmlElement MapElem = (XmlElement)MapNode; //Label1.Text = WsmsElem.GetAttribute("Version").ToString(); int WsmsVersion = int.Parse(WsmsElem.GetAttribute("Version").ToString()); int MapVersion = int.Parse(MapElem.GetAttribute("Version").ToString()); if (WsmsVersion > MapVersion)//对比版本号,如果是最新的 { WsmsXmlDoc.Save(Server.MapPath("~/") + MapXmlUrl);//将异地的WsmsXmlDoc保存到Server.MapPath("~/") + MapXmlUrl文件中(此处不能用Server,如果非用Server不可,改用.aspx页面的操作处理) } }
如有什么不足,欢迎指点!!