当前位置导航:炫浪网>>网络学院>>网页制作>>XML/WebService教程

在.NET 3.5下,异步调用Web Service

        今天发现,在.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();
        }
        }

        输出:
        step1

        zhenglanzhen

        step2

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

        输出:

        step1

        step2

        zhenglanzhen

相关内容
赞助商链接