WebService 的簡單使用

來源:互聯網
上載者:User

標籤:互動   .com   效果   double   16px   end   idt   src   ges   

簡單介紹

WebService是一種跨語言,跨進程,跨機器的資料互動技術。

SOAP:簡易物件存取通訊協定 (SOAP),通過XML資料互動的輕量級協議,WebService就是採用的這種協議

WSDL:web服務描述語言,描述了服務API的參數以及返回結果等資訊

WebService的的使用

1.首先建立一個空的web項目,然後添加“web服務”,這個檔案的尾碼名是asmx

2.建立一個WindowsForm項目,可以建立任何類型的項目

  private void button1_Click(object sender, EventArgs e)        {            if (string.IsNullOrEmpty(txtOne.Text) || string.IsNullOrEmpty(txtTwo.Text))            {                MessageBox.Show("請輸入正確的數值");            }            else            {                double one = double.Parse(txtOne.Text);                double two = double.Parse(txtTwo.Text);                SumServiceReference.WebService1SoapClient client = new SumServiceReference.WebService1SoapClient();                double result=  client.Add(one, two);                txtResult.Text = result.ToString();            }        }

天氣預報的WebServie介面的使用

1.添加天氣預報的服務引用

 

 2.此時運行程式的時候會出現錯誤

 

因為此時需要添加Web引用,具體的操作:加入服務參考——》進階——》添加web引用

 

 3.實現的效果

4.實現的代碼

 1  private void button2_Click(object sender, EventArgs e) 2         { 3             txtContent.Clear(); 4             if (!string.IsNullOrEmpty(txtCity.Text)) 5             { 6                 WebWeatherService.WeatherWebService weatherService = new WebWeatherService.WeatherWebService(); 7                 string[] content=weatherService.getWeatherbyCityName(txtCity .Text); 8                 foreach (string str in content) 9                 {10                     txtContent.AppendText(str + "\n");11                 }12             }13         }

 

WebService 的簡單使用

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.