/// <summary> /// Caches a web method definition /// </summary> /// <param name="wsType"></param> /// <param name="methods"></param> /// <param name="method"></param> private void AddMethod(Type wsType, Dictionary <string, WebMethodDef> methods, MethodInfo method) { object[] wmAttribs = method.GetCustomAttributes(typeof(WebMethodAttribute), false); if (wmAttribs.Length == 0) { return; } ScriptMethodAttribute sm = null; object[] responseAttribs = method.GetCustomAttributes(typeof(ScriptMethodAttribute), false); if (responseAttribs.Length > 0) { sm = (ScriptMethodAttribute)responseAttribs[0]; } TransactionalMethodAttribute tm = null; object[] tmAttribs = method.GetCustomAttributes(typeof(TransactionalMethodAttribute), false); if (tmAttribs.Length > 0) { tm = (TransactionalMethodAttribute)tmAttribs[0]; } WebMethodDef wmd = new WebMethodDef(this, method, (WebMethodAttribute)wmAttribs[0], sm, tm); methods[wmd.MethodName] = wmd; }
public WebMethodDef(WebServiceDef wsDef, MethodInfo method, WebMethodAttribute wmAttribute, ScriptMethodAttribute smAttribute, TransactionalMethodAttribute tmAttribute, ETagMethodAttribute emAttribute) { this.MethodType = method; this.WebMethodAtt = wmAttribute; this.ScriptMethodAtt = smAttribute; this.TransactionAtt = tmAttribute; if (null != emAttribute) { this.IsETagEnabled = emAttribute.Enabled; } if (wmAttribute != null && !string.IsNullOrEmpty(wmAttribute.MessageName)) { this.MethodName = wmAttribute.MessageName; } else { this.MethodName = method.Name; } // HTTP GET method is allowed only when there's a [ScriptMethod] attribute and UseHttpGet is true this.IsGetAllowed = (this.ScriptMethodAtt != null && this.ScriptMethodAtt.UseHttpGet); this.ResponseFormat = (this.ScriptMethodAtt != null ? this.ScriptMethodAtt.ResponseFormat : ResponseFormat.Json); MethodInfo beginMethod = wsDef.WSType.GetMethod("Begin" + method.Name, BINDING_FLAGS); if (null != beginMethod) { // The BeginXXX method must have the [ScriptMethod] attribute object[] scriptMethodAttributes = beginMethod.GetCustomAttributes(typeof(ScriptMethodAttribute), false); if (scriptMethodAttributes.Length > 0) { // Asynchronous methods found for the function this.HasAsyncMethods = true; this.BeginMethod = new WebMethodDef(wsDef, beginMethod, null, null, null, null); MethodInfo endMethod = wsDef.WSType.GetMethod("End" + method.Name, BINDING_FLAGS); this.EndMethod = new WebMethodDef(wsDef, endMethod, null, null, null, null); // get all parameters of begin web method and then leave last two parameters in the input parameters list because // last two parameters are for AsyncCallback and Async State ParameterInfo[] allParameters = beginMethod.GetParameters(); ParameterInfo[] inputParameters = new ParameterInfo[allParameters.Length - 2]; Array.Copy(allParameters, inputParameters, allParameters.Length - 2); this.BeginMethod.InputParameters = new List <ParameterInfo>(inputParameters); this.BeginMethod.InputParametersWithAsyc = new List <ParameterInfo>(allParameters); } } this.InputParameters = new List <ParameterInfo>(method.GetParameters()); }
public WebMethodDef(WebServiceDef wsDef, MethodInfo method, WebMethodAttribute wmAttribute, ScriptMethodAttribute smAttribute, TransactionalMethodAttribute tmAttribute, ETagMethodAttribute emAttribute) { this.MethodType = method; this.WebMethodAtt = wmAttribute; this.ScriptMethodAtt = smAttribute; this.TransactionAtt = tmAttribute; if( null != emAttribute ) this.IsETagEnabled = emAttribute.Enabled; if (wmAttribute != null && !string.IsNullOrEmpty(wmAttribute.MessageName)) this.MethodName = wmAttribute.MessageName; else this.MethodName = method.Name; // HTTP GET method is allowed only when there's a [ScriptMethod] attribute and UseHttpGet is true this.IsGetAllowed = (this.ScriptMethodAtt != null && this.ScriptMethodAtt.UseHttpGet); this.ResponseFormat = (this.ScriptMethodAtt != null ? this.ScriptMethodAtt.ResponseFormat : ResponseFormat.Json); MethodInfo beginMethod = wsDef.WSType.GetMethod("Begin" + method.Name, BINDING_FLAGS); if (null != beginMethod) { // The BeginXXX method must have the [ScriptMethod] attribute object[] scriptMethodAttributes = beginMethod.GetCustomAttributes(typeof(ScriptMethodAttribute), false); if (scriptMethodAttributes.Length > 0) { // Asynchronous methods found for the function this.HasAsyncMethods = true; this.BeginMethod = new WebMethodDef(wsDef, beginMethod, null, null, null, null); MethodInfo endMethod = wsDef.WSType.GetMethod("End" + method.Name, BINDING_FLAGS); this.EndMethod = new WebMethodDef(wsDef, endMethod, null, null, null, null); // get all parameters of begin web method and then leave last two parameters in the input parameters list because // last two parameters are for AsyncCallback and Async State ParameterInfo[] allParameters = beginMethod.GetParameters(); ParameterInfo[] inputParameters = new ParameterInfo[allParameters.Length - 2]; Array.Copy(allParameters, inputParameters, allParameters.Length - 2); this.BeginMethod.InputParameters = new List<ParameterInfo>(inputParameters); this.BeginMethod.InputParametersWithAsyc = new List<ParameterInfo>(allParameters); } } this.InputParameters = new List<ParameterInfo>(method.GetParameters()); }