欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: 用VB.NET 2005玩一次Web Service [打印本頁(yè)]

作者: liuzhu    時(shí)間: 2015-9-12 21:52
標(biāo)題: 用VB.NET 2005玩一次Web Service
最近做服務(wù)器,需要獲取天氣信息,想到了Web Service,以前還沒有用過(guò),這次用了之后感覺很不錯(cuò),就是相當(dāng)于遠(yuǎn)程的函數(shù)調(diào)用,記錄如下。
1. 添加winform工程MyTest01,在右邊“解決方案資源管理器”的工程文件上點(diǎn)擊右鍵,選擇“添加Web引用”.

2. 在彈出的“添加web引用”對(duì)話框中,URL地址里面輸入提供web Service的服務(wù)器地址,http://www.webxml.com.cn/WebServices/WeatherWebService.asmx,點(diǎn)擊“前往”按鈕,系統(tǒng)提示“找到1個(gè)服務(wù):WeatherWebService”,將我們使用的Web引用名修改為weather,這樣子不用系統(tǒng)默認(rèn)那么長(zhǎng)的一大串名字。添加該引用。

3. 系統(tǒng)會(huì)自動(dòng)打開“對(duì)象瀏覽器”,選擇MyTest01.Weather,看看這個(gè)WebService都有哪些方法吧。

4.Form1窗口界面上,添加如下控件:

5.在Form1.vb里面添加代碼,實(shí)現(xiàn)天氣預(yù)報(bào)的功能。
Imports MyTest01.Weather

Public Class Form1
    Dim MyWeather As Weather.WeatherWebService = New Weather.WeatherWebService()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim tmpStr(0 To 23) As String
        tmpStr = MyWeather.getWeatherbyCityName(Cmb_City.Text.Substring(0, Cmb_City.Text.IndexOf(" ")))
        If (tmpStr(8) = "") Then
            MessageBox.Show("暫時(shí)不支持您查詢的城市")
        Else
            Label1.Text = "天氣概況:" & tmpStr(1) & " " & tmpStr(6)
            TextBox1.Text = tmpStr(10)
            TextBox2.Text = tmpStr(11)
            TextBox3.Text = tmpStr(13) & "," & tmpStr(12) & "," & tmpStr(14) & vbCrLf & tmpStr(18) & "," & tmpStr(17) & "," & tmpStr(19)
            TextBox4.Text = tmpStr(22)
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim ProvinceStr() As String
        Dim i As Integer
        ProvinceStr = MyWeather.getSupportProvince()
        For i = ProvinceStr.GetLowerBound(0) To ProvinceStr.GetUpperBound(0)
            Cmb_Province.Items.Add(ProvinceStr(i))
        Next

        Cmb_Province.Text = ProvinceStr(0)

    End Sub

    Private Sub Cmb_Province_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmb_Province.SelectedIndexChanged
        Dim CityStr() As String
        Dim i As Integer
        CityStr = MyWeather.getSupportCity(Cmb_Province.Text)
        For i = CityStr.GetLowerBound(0) To CityStr.GetUpperBound(0)
            Cmb_City.Items.Add(CityStr(i))
        Next
        Cmb_City.Text = CityStr(0)
    End Sub
End Class
6.運(yùn)行結(jié)果:

好玩的實(shí)用的WebService還有很多,不過(guò)好多都需要掏錢了。






歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1