当前位置:编程学习 > asp >>

VS中使用各种Web服务

<body>
 <form id="form1" runat="server">
 <div>
 
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
Xonselectedindexchanged="DropDownList1_SelectedIndexChanged">
 </asp:DropDownList>
 <asp:DropDownList ID="DropDownList2" runat="server">
 </asp:DropDownList>
 
 <asp:Button ID="btnChaKan" runat="server" Xonclick="btnChaKan_Click" Text="查看" />
   
 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
 
</div>
 </form>
</body>
---------WebTianQi.aspx-后台------------
 protected void Page_Load(object sender, EventArgs e)
 {
 if (!IsPostBack)
 {
 cn.com.webxml.www.WeatherWebService weather = new 
 
cn.com.webxml.www.WeatherWebService();
 this.DropDownList1.DataSource=weather.getSupportProvince();
 this.DropDownList1.DataBind();
 }
 
}
 
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
 {
 cn.com.webxml.www.WeatherWebService weather = new cn.com.webxml.www.WeatherWebService();
 BindCity(weather);
 }
 
private void BindCity(cn.com.webxml.www.WeatherWebService weather)
 {
 this.DropDownList2.Items.Clear();
 string[] strs = weather.getSupportCity(this.DropDownList1.SelectedValue);
 foreach (string item in strs)
 {
 DropDownList2.Items.Add(new ListItem(item.Substring(0, item.IndexOf("("))));
 }
 }
 
protected void btnChaKan_Click(object sender, EventArgs e)
 {
 cn.com.webxml.www.WeatherWebService weather = new cn.com.webxml.www.WeatherWebService();
 string[] strs=weather.getWeatherbyCityName(this.DropDownList2.SelectedValue);
 this.Label1.Text = strs[0] + ":"+strs[1] + ":<br/>";
 this.Label1.Text += "气温:" + strs[5] + ";风向和风力:" + strs[7];
 }
 
 
=================• 列车时刻表查询 ===============================
 
------------WebLieCheShiKeBiao.aspx前台------ 
<body>
 <form id="form1" runat="server">
 <div>
 
<br />
 发车站:<asp:TextBox ID="txtFaCheZhan" runat="server"></asp:TextBox>
 <br />
 到达站:<asp:TextBox ID="txtDaoDaZhan" runat="server"></asp:TextBox>
 
<br />
 UserId:<asp:TextBox ID="txtUserId" runat="server"></asp:TextBox>
 <span>商业用户ID(普通用户不需要)</span><br />
 <asp:Button ID="btnChaXun" runat="server" Xonclick="btnChaXun_Click" Text="查询" />
 <br />
 <br />
 <asp:GridView ID="GridView1" runat="server">
 </asp:GridView>
 
</div>
 </form>
</body>
 
-----------WebLieCheShiKeBiao.aspx.cs后台-----------------
 
protected void btnChaXun_Click(object sender, EventArgs e)
 {
 cn.com.webxml.www1.TrainTimeWebService train = new 
 
cn.com.webxml.www1.TrainTimeWebService();
 DataSet ds=train.getStationAndTimeByStationName(txtFaCheZhan.Text, txtDaoDaZhan.Text,
 
txtUserId.Text);
 
this.GridView1.DataSource = ds;
 this.GridView1.DataBind();
 }
 
==========================• 电话号码查询 ==========================
 
--------WebDianHuaHaoMa.aspx前台---------- 
<body>
 <form id="form1" runat="server">
 <div>
 请输入手机号码:<asp:TextBox ID="txtHaoMa" runat="server"></asp:TextBox>
 
<br />
 userID:<asp:TextBox ID="txtUserId" runat="server"></asp:TextBox>
 <span>商业用户ID不用填写<br />
 </span>
 <asp:Button ID="btnChaXun" runat="server" Xonclick="btnChaXun_Click" Text="查询" />
 <br />
 <asp:Label ID="Label1" runat="server"></asp:Label>
 
</div>
 </form>
</body>
 
--------WebDianHuaHaoMa.aspx.cs后台-------
 protected void btnChaXun_Click(object sender, EventArgs e)
 {
 cn.com.webxml.webservice.MobileCodeWS mobile = new cn.com.webxml.webservice.MobileCodeWS
 
();
 Label1.Text= mobile.getMobileCodeInfo(txtHaoMa.Text, txtUserId.Text);
 }
 
 
==========================• 中英文翻译==========================
 
------WebZhongYingWenFanYi.aspx前台------------------------
<body>
 <form id="form1" runat="server">
 <div>
 请输入英文或中文:<asp:TextBox ID="txtWord" runat="server"></asp:TextBox>
 <asp:Button ID="btnFanYi" runat="server" Text="翻译" Xonclick="btnFanYi_Click" />
 <br />
 <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
 </div>
 </form>
</body>
 
------WebZhongYingWenFanYi.aspx.cs后台------------------------
 
protected void btnFanYi_Click(object sender, EventArgs e)
 {
 cn.com.webxml.www2.TranslatorWebService translator = new 
 
cn.com.webxml.www2.TranslatorWebService();
 string[] strs=translator.getEnCnTwoWayTranslator(txtWord.Text);
 Label1.Text = strs[0] + ";" + strs[1];
 }
 
==========================• 验证码图片==========================
 
 
--------WebYanZhengMa.aspx前台----------------------
<body>
 <form id="form1" runat="server">
 <div>
 请输入验证码(为英文/数字)
 <asp:TextBox ID="txtYZM" runat="server"></asp:TextBox>
 <br />补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,