异步调用Web Service

VS2008、C#

今天发现,在.NET 3.5下,异步调用Web Service与以往似乎有些不同。现在生成的代理类少了 BeginXXX 方法,Why?

1. Web Service
[WebMethod]
        
public string GetUserName() {
            
return "zhenglanzhen";
        }

2. 同步调用
class Program {
        
static void Main(string[] args) {
            Console.WriteLine(
"step1");
            NameServiceProxy.NameService n 
= new NameServiceProxy.NameService();
            Console.WriteLine(n.GetUserName());
            Console.WriteLine(
"step2");
            Console.Read();
        }

    }

输出:
    

3. 异步调用
class Program {
        
static void Main(string[] args) {
            Console.WriteLine(
"step1");
            NameServiceProxy.NameService n 
= new NameServiceProxy.NameService();
            n.GetUserNameCompleted 
+= delegate(object sender, GetUserNameCompletedEventArgs e) {
                Console.WriteLine(e.Result);
            }
;
            n.GetUserNameAsync();
            Console.WriteLine(
"step2");
            Console.Read();
        }

    }

输出:

    
posted on 2008-01-28 16:00  Tristan(GuoZhijian)  阅读(481)  评论(3编辑  收藏  举报