u011120525 2014年01月07日
求指点。在做一个webserver 供app调用数据,现在思路不是很清楚该干什么了
一个app 调用我网站的产品数据,我生成了 一个 xml 文件用来供app调用
这是xml文件
<?xml version="1.0" encoding="utf-8"?>
<root>
<product id="54">
<name>【推荐】加拿大原装进口冰酒 伏特加·冰酒·马提尼洗涤你的灵魂</name>
<id>54</id>
<price>0</price>
<spgg>
</spgg>
<spbg>加拿大原装进口</spbg>
<spzt>1</spzt>
<img1>files/0TNJE1.jpg</img1>
<img2>files/P17GBQ.jpg</img2>
<img3>files/C633NL.jpg</img3>
<img4>files/99TP31.jpg</img4>
<img5>files/OUIW8L.jpg</img5>
<img6>files/IAFQSM.jpg</img6>
<img7>
</img7>
</product>
<product id="51">
<name>【推荐】世界首款负离子混血儿植物汤茶 美国FDA首款植物茶</name>
<id>51</id>
<price>268</price>
<spgg>
</spgg>
<spbg>90克(15*6克)</spbg>
<spzt>1</spzt>
<img1>files/AIKQK2.jpg</img1>
<img2>files/E04HAG.jpg</img2>
<img3>files/R2H43J.jpg</img3>
<img4>files/OOFRXM.jpg</img4>
<img5>files/DONSM4.jpg</img5>
<img6>files/BTRTYU.jpg</img6>
<img7>files/YU3RHK.jpg</img7>
</product>
<product id="48">
<name>【推荐】徒河黑猪排骨礼盒 肌红蛋白含量高、亚油酸含量高</name>
<id>48</id>
<price>298</price>
<spgg>
</spgg>
<spbg>排骨礼盒</spbg>
<spzt>1</spzt>
<img1>files/P0MBW4.jpg</img1>
<img2>files/5DT474.jpg</img2>
<img3>files/7USA1U.jpg</img3>
<img4>files/LTTTK6.jpg</img4>
<img5>files/V7PKV5.jpg</img5>
<img6>files/HMF9YW.jpg</img6>
<img7>files/GFFKVB.jpg</img7>
</product>
<product id="46">
<name>【推荐】家用空调专用清洗液 杀菌除臭防疾病</name>
<id>46</id>
<price>69</price>
<spgg>
</spgg>
<spbg>400ml/瓶</spbg>
<spzt>1</spzt>
<img1>files/TQD5O4.jpg</img1>
<img2>files/LW7V6Q.jpg</img2>
<img3>files/UPE62V.jpg</img3>
<img4>files/0CO6TC.jpg</img4>
<img5>files/NATJ6D.jpg</img5>
<img6>files/UEEDNH.jpg</img6>
<img7>files/OGLUW9.jpg</img7>
</product>
<product id="45">
<name>【推荐】家居用清洁液 去污、杀菌、去静电、除异味</name>
<id>45</id>
<price>69</price>
<spgg>
</spgg>
<spbg>加电水/NO:1号</spbg>
<spzt>1</spzt>
<img1>files/8SWAPJ.jpg</img1>
<img2>files/JKRXK1.jpg</img2>
<img3>files/EC4BD6.jpg</img3>
<img4>files/7SB18F.jpg</img4>
<img5>files/R73V9M.jpg</img5>
<img6>files/NHYABI.jpg</img6>
<img7>files/U8GIO6.jpg</img7>
</product>
<product id="44">
<name>【推荐】全民付A30 MINI型POS终端 快捷支付 便利生活</name>
<id>44</id>
<price>698</price>
<spgg>
</spgg>
<spbg>A30 MINI</spbg>
<spzt>1</spzt>
<img1>files/JFGC0J.jpg</img1>
<img2>files/NIENSE.jpg</img2>
<img3>files/Q7WMK1.jpg</img3>
<img4>files/11GKP6.jpg</img4>
<img5>files/IRNJF5.jpg</img5>
<img6>files/LBX8LY.jpg</img6>
<img7>
</img7>
</product>
<product id="43">
<name>【推荐】飞利浦多功能弹性洁面仪双刀头电动剃须刀 干湿两用</name>
<id>43</id>
<price>699</price>
<spgg>
</spgg>
<spbg>YS526</spbg>
<spzt>1</spzt>
<img1>files/AXVXMK.jpg</img1>
<img2>files/VQETGD.jpg</img2>
<img3>files/8LP420.jpg</img3>
<img4>files/CMG1NW.jpg</img4>
<img5>files/YWIXQM.jpg</img5>
<img6>files/2E8B23.jpg</img6>
<img7>files/DROCSF.jpg</img7>
</product></root>



这是 webserver.cs 文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using System.Xml.Linq;
using System.Xml;
/// <summary>
///WebService 的摘要说明
/// </summary>
//[WebService(Namespace = "http://tempuri.org/")]
[WebService(Namespace = "http://contoso.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

DbExec db = new DbExec();
public WebService () {

//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}


[WebMethod]
public string Getlist()
{
XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(Server.MapPath("products.xml"));


DataTable dt = db.getDataTable("select * from products where uid=0 order by weizhi asc,id desc");
if (dt != null && dt.Rows.Count > 0)
{


XmlNode xmldocselect = xmlDoc.SelectSingleNode("root");
xmldocselect.RemoveAll();


for (int i = 0; i < dt.Rows.Count; i++)
{
XmlElement el = xmlDoc.CreateElement("product");
el.SetAttribute("id", dt.Rows[i]["id"].ToString());

XmlElement elname = xmlDoc.CreateElement("name");
elname.InnerText = dt.Rows[i]["name"].ToString();
el.AppendChild(elname);

XmlElement elid = xmlDoc.CreateElement("id");
elid.InnerText = dt.Rows[i]["id"].ToString();
el.AppendChild(elid);

XmlElement elprice = xmlDoc.CreateElement("price");
elprice.InnerText = dt.Rows[i]["scjg"].ToString();
el.AppendChild(elprice);

XmlElement elspgg = xmlDoc.CreateElement("spgg");
elspgg.InnerText = dt.Rows[i]["spgg"].ToString();
el.AppendChild(elspgg);

XmlElement elspbh = xmlDoc.CreateElement("spbg");
elspbh.InnerText = dt.Rows[i]["spbh"].ToString();
el.AppendChild(elspbh);

XmlElement elspzt = xmlDoc.CreateElement("spzt");
elspzt.InnerText = dt.Rows[i]["spzt"].ToString();
el.AppendChild(elspzt);

XmlElement elimg1 = xmlDoc.CreateElement("img1");
elimg1.InnerText = dt.Rows[i]["img1"].ToString();
el.AppendChild(elimg1);

XmlElement elimg2 = xmlDoc.CreateElement("img2");
elimg2.InnerText = dt.Rows[i]["img2"].ToString();
el.AppendChild(elimg2);


XmlElement elimg3 = xmlDoc.CreateElement("img3");
elimg3.InnerText = dt.Rows[i]["img3"].ToString();
el.AppendChild(elimg3);

XmlElement elimg4 = xmlDoc.CreateElement("img4");
elimg4.InnerText = dt.Rows[i]["img4"].ToString();
el.AppendChild(elimg4);

XmlElement elimg5 = xmlDoc.CreateElement("img5");
elimg5.InnerText = dt.Rows[i]["img5"].ToString();
el.AppendChild(elimg5);

XmlElement elimg6 = xmlDoc.CreateElement("img6");
elimg6.InnerText = dt.Rows[i]["img6"].ToString();
el.AppendChild(elimg6);

XmlElement elimg7 = xmlDoc.CreateElement("img7");
elimg7.InnerText = dt.Rows[i]["img7"].ToString();
el.AppendChild(elimg7);

xmldocselect.AppendChild(el);
}

xmlDoc.Save(Server.MapPath("products.xml"));






return //

}





现在我不知道 return 什么了东西了。xml文件怎么返回呢? 还有 都在说 post、get、等一些调用方法 我该怎么去开发呢?

能不能给我一些短暂的指点,或者相关的参考资料呢,谢谢了
...全文
444 点赞 收藏 3
写回复
3 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Web Services
创建于2007-09-28

1.1w+

社区成员

1.6w+

社区内容

.NET技术 Web Services
社区公告
暂无公告