然後編寫Windows用戶端和Web用戶端消費該服務

來源:互聯網
上載者:User
web|window|用戶端 為了體現XMLWebService的可跨越異質平台、與系統無關與裝置無關與消費者的應用程式類型無關等特性。
給學生示範了用C#編寫一個Windows程式來消費該服務的例子:

代碼很簡單,只是添加如下幾行而已:
private void button1_Click(object sender, System.EventArgs e)
{
Get.Service1 AA=new WS03.Get.Service1();
string score=AA.GetScore(comboBox1.SelectedItem.ToString(),comboBox2.SelectedItem.ToString()).ToString();
label3.Text="學生"+comboBox1.SelectedItem.ToString()+"的"+comboBox2.SelectedItem.ToString()+"成績是:"+score;
}

private void button2_Click(object sender, System.EventArgs e)
{
Get.Service1 AA=new WS03.Get.Service1();
string average=AA.GetAverage(comboBox1.SelectedItem.ToString()).ToString();
label4.Text="學生"+comboBox1.SelectedItem.ToString()+"的平均分是:"+average;
}

private void button3_Click(object sender, System.EventArgs e)
{
Get.Service1 AA=new WS03.Get.Service1();
string order=AA.GetOrder(comboBox1.SelectedItem.ToString()).ToString();
label5.Text="學生"+comboBox1.SelectedItem.ToString()+"的排名是:第"+order+"名";
}


然後再用VB.NET編寫一個ASP.NET程式來調用該服務:

代碼也是非常的簡單:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim AA As New [Get].Service1
Label1.Text = AA.GetScore(DropDownList1.SelectedItem.Text, DropDownList2.SelectedItem.Text)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim AA As New [Get].Service1
Label2.Text = AA.GetAverage(DropDownList1.SelectedItem.Text)
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim AA As New [Get].Service1
Label3.Text = AA.GetOrder(DropDownList1.SelectedItem.Text)
End Sub
當然在這兩個程式裡都不要忘記添加進該Web引用,在本地產生SOAP代理,只不過有很多的工作都由VS.NET這個IDE給完成了。
如果是使用WebMatrix來編寫ASP.NET消費Web服務的話,可就有一番工作需要你自己完成了,這個等下次再講。




相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.