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

首頁 > 編程 > .NET > 正文

體驗(yàn).net 2.0 的優(yōu)雅 - 異步WebService調(diào)用

2024-07-10 13:12:06
字體:
供稿:網(wǎng)友
   在.net2.0中(準(zhǔn)確的說是vs 2005中),異步webservice異步調(diào)用的方式的例子:

 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);
            }
       }

    服務(wù)器端代碼

 [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 這兩個煩人的東西,調(diào)用的代碼變得簡潔、優(yōu)雅了,而且可以從e.result得到強(qiáng)類型的返回值(上例為"hello world")。但是,有興趣的話,可以看看vs 2005生成的referance.cs文件,那可比2003中的復(fù)雜很多。其中可以看到system.componentmodel.asynccompletedeventargs 、 system.threading.sendorpostcallback(delegate)這兩個在 .net 1.x 中沒有的“怪物”,估計(jì)用到的地方還不止webservice客戶端。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 武城县| 东阿县| 临西县| 拜城县| 江西省| 奉节县| 伊春市| 滦平县| 河津市| 开原市| 绍兴县| 遂川县| 白朗县| 芦山县| 陕西省| 大新县| 齐河县| 永德县| 彰武县| 景泰县| 宜章县| 新乐市| 花垣县| 靖宇县| 奈曼旗| 那曲县| 道真| 礼泉县| 丰顺县| 昌江| 河北省| 大庆市| 朝阳县| 兴仁县| 长葛市| 平顺县| 赤壁市| 黄陵县| 常宁市| 邵武市| 上饶市|