下面的这个例子演示了web service是如何初始化的:
1.创建测试用的web service.
 1web service类什么时候初始化?using System;
 2web service类什么时候初始化?using System.Web;
 3web service类什么时候初始化?using System.Web.Services;
 4web service类什么时候初始化?using System.Web.Services.Protocols;
 5web service类什么时候初始化?using System.IO;
 6web service类什么时候初始化?
 7web service类什么时候初始化?[WebService(Namespace = "http://tempuri.org/")]
 8web service类什么时候初始化?[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
 9web service类什么时候初始化?public class Service : System.Web.Services.WebService
10
从代码中可以看出,在服务器的构造函数中只是在一个文件中记录了当前服务器的时间和一共调用了web service的次数.
注意:必须给对应的目录添加对ASPNET帐号的写权限,否则会出现访问拒绝的异常.

2.创建客户端测试代码
 1web service类什么时候初始化?using System;
 2web service类什么时候初始化?using System.Collections.Generic;
 3web service类什么时候初始化?using System.ComponentModel;
 4web service类什么时候初始化?using System.Data;
 5web service类什么时候初始化?using System.Drawing;
 6web service类什么时候初始化?using System.Text;
 7web service类什么时候初始化?using System.Windows.Forms;
 8web service类什么时候初始化?using System.Net;
 9web service类什么时候初始化?
10web service类什么时候初始化?namespace WSTest
11}

只是一个简单的win form程序,你可以通过两个按钮按不同的次序调用两个web method,然后看生成的文件里记录的信息.

3.下面是生成的文本文件的截图.

.web service类什么时候初始化?

4. 结论
 web service在每一个请求来之前都会重新初始化一次,每调用其中的一个web method都会造成web service被重新初始化.

相关文章: