国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 黄大仙区| 元阳县| 万全县| 龙州县| 军事| 时尚| 布拖县| 晋江市| 高淳县| 泰宁县| 平舆县| 砚山县| 江津市| 江都市| 胶南市| 五峰| 汾阳市| 永济市| 玛纳斯县| 镇原县| 钦州市| 溧阳市| 老河口市| 濉溪县| 庄河市| 仙居县| 贺州市| 九寨沟县| 富锦市| 潜山县| 宁武县| 尼勒克县| 盐池县| 海丰县| 鱼台县| 长葛市| 娄底市| 瑞丽市| 本溪市| 房产| 广元市|