设为首页 收藏本站 English

当前位置: 巩义体育网 >> 亚冠

深入系列之服务器端支持的

发布时间:2021-09-06 10:11:41

对于开发人员来说,它的价值就是:我们能够把一个Web Service方法的请求处理编译在程序集之中!例如,我们只需要写一个mpleService类继承bService,并在Javascript中请求“ScriptServices/Jeffz/Atlas/mx”即可。这对于发布和部署组建提供了非常大的便利,对于喜欢编写Extender的朋友们,也提供了和服务器端交互的完美方式。关于这一点,我会在这一系列接下去的文章中给与具体的范例供大家参考。

继续回到对代码的分析,GetWebServiceData(string, bool)最终是返回了GetWebServiceData(Type)调用结果。代码如下:

GetWebServiceData(Type)方法分析:

1 private static WebServiceData GetWebServiceData(Type type)

2 {

3 // 设法从Cache内获得WebServiceData对象

4 WebServiceData data = WebServiceData._cache[type] as WebServiceData;

5

6 // 如果Cache内没有

7 if (data == null)

8 {

9 // 构造该对象

10 data = new WebServiceData(type);

11 // 并放入Cache中

12 WebServiceData._cache[type] = data;

13 }

14

15 return data;

16 }

代码非常简单,就不多作解释了。WebServiceData类的构造函数也无需分析,只是简单的保留那个Type而已。代码如下:

WebServiceData构造函数:

推动地方建立疾病应急救助制度 1 private WebServiceData(Type type)

2 {

3 this._type = type;

4 }

WebServiceData类的分析到这里先告一段落,我们回到之前的代码。获得IHttpHandler对象是调用了RestHandler的CreateHandler(WebServiceData, string)静态方法,代码如下:

CreateHandler(WebServiceData, string)静态方法分析:

1 private static IHttpHandler CreateHandler(WebServiceData webServiceData, string methodName)

2 {

3 RestHandler handler;

4 // 调用GetMethodData得到WebServiceMethodData对象实例,

5 // 描述了一个Web Service方法。

6 WebServiceMethodData data = tMethodData(methodName);

7

8 // 根据是否支持Session选择不同的Handler

9 if (quiresSession)

10 {

11 handler = new RestHandlerWithSession();

12 }

13 else

14 {

15 handler = new RestHandler();

16 }

17

18 handler._webServiceMethodData = data;

19 return handler;

20 }

这里出现了对于Web Services方法的描述类WebServiceMethodData,通过WebServiceData的GetMethodData方法获得。该方法代码如下:

GetMethodData方法分析:

1 internal WebServiceMethodData GetMethodData(string methodName)

2 {

3 // 保证Method的描述都被加载并保存了

4 sureMethods();

5

6 WebServiceMethodData data = this._methods[methodName];

7 if (data == null)

8 {

9 throw new ArgumentException(rmat(rrentCulture, knownWebMethod, new object[] { methodName }), \"methodName\");

10 }

11

12 return data;

13 }

sureMethod()方法通过反射得到了Web Service中类的方法信息并保存下来,代码如下:

EnsureMethod方法分析:

1 private void EnsureMethods()

2 {

3 if (this._methods == null)

4 {

5 lock (this)

6 {

7 Dictionary<string, WebServiceMethodData> methodDict =

8 new Dictionary<string, WebServiceMethodData>(dinalIgnoreCase);

9

10 // 获得所有public的实例方法

11 MethodInfo[] infoArray = this._tMethods(blic | stance);

12

13 // 枚举每个MethodInfo

14 foreach (MethodInfo info in infoArray)

15 {

16 // 获得WebMethodAttribute标注

17 object[] webMethodAttArray = tCustomAttributes(typeof(WebMethodAttribute), true);

18

19 // 如果这个方法被WebMethodAttribute标注了

20 if (ngth != 0)

21 {

22 // 获得WebOperationAttribute标注

23 object[] webOpAttArray = tCustomAttributes(typeof(WebOperationAttribute), true);

24

25 // 生成WebServiceMethodData对象

26 WebServiceMethodData data = new WebServiceMethodData(

27 this,

28 info,

29 (WebMethodAttribute)webMethodAttArray[0],

30 (ngth != 0) ? ((WebOperationAttribute)webOpAttArray[0]) : null);

31

32 // 放入Dictionary

33 methodDict[] = data;

34 }

35 }

36

37 this._methods = methodDict;

38 }

39 }

40 }

代码运行到此处,已经获得要执行的那个方法。马上就要进入了Handler的ProcessRequest阶段了,在那里会对接受这个请求的输入,并提供输出。那么它就是如何工作的呢?

查看本文来源

醒脾养儿颗粒
成都免疫性不孕医院
拉萨男科医院哪家医院好
友情链接