国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

體驗.NET 2.0的優雅之異步Web服務調用

2019-11-17 04:41:22
字體:
來源:轉載
供稿:網友

  在.net1.x中,異步WebService異步調用的一般方式為調用方法XX對應的BeginXX方法來完成,其過程類似于異步委托的使用。

  在.net2.0中(準確的說是vs.net 2005中),異步WebService異步調用的方式的例子:

void DoSomethingTest()
{
 localhost.Service service = new WindowsApp.localhost.Service();

 service.HelloWorldCompleted += new WindowsApp.localhost.HelloWorldCompletedEventHandler(service_HelloWorldCompleted);
 // do Asyn calling here
 service.HelloWorldAsync();
}

void service_HelloWorldCompleted(object sender, WindowsApp.localhost.HelloWorldCompletedEventArgs e)
{
 if (e.Error == null)
 {
  MessageBox.Show(e.Result);
 }
 else
 {
  MessageBox.Show(e.Error.Message);
 }
}
  服務器端代碼

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = Wsiprofiles.BasicPRofile1_1)]
public class Service : System.Web.Services.WebService
{
 public Service () {}

 [WebMethod]
 public string HelloWorld() {
  return "Hello World";
 }
}
  很簡單,沒有了AsyncCallback、IAsyncResult 這兩個煩人的東西,調用的代碼變得簡潔、優雅了,而且可以從e.Result得到強類型的返回值(上例為"Hello World")。但是,有愛好的話,可以看看vs.net2005生成的Referance.cs文件,那可比2003中的復雜很多。其中可以看到System.ComponentModel.AsyncCompletedEventArgs 、 System.Threading.SendOrPostCallback(delegate)這兩個在 .net 1.x 中沒有的“怪物”,估計用到的地方還不止WebService客戶端。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 涡阳县| 孟津县| 鹤壁市| 阳高县| 乐山市| 嵩明县| 漯河市| 东港市| 胶州市| 临清市| 中方县| 比如县| 米脂县| 永昌县| 冕宁县| 马山县| 沙洋县| 简阳市| 鹰潭市| 行唐县| 韶山市| 银川市| 威信县| 惠州市| 陆良县| 阳西县| 高台县| 南和县| 宝应县| 漳浦县| 永春县| 南漳县| 奉新县| 丽水市| 天镇县| 佛山市| 花莲县| 邳州市| 钟祥市| 东海县| 楚雄市|