public LogicalMethodInfo (LogicalTypeInfo typeInfo, MethodInfo method) {
				_typeInfo = typeInfo;
				_methodInfo = method;

				_wma = (WebMethodAttribute) Attribute.GetCustomAttribute (method, typeof (WebMethodAttribute));

				_sma = (ScriptMethodAttribute) Attribute.GetCustomAttribute (method, typeof (ScriptMethodAttribute));
				if (_sma == null)
					_sma = ScriptMethodAttribute.Default;

				_params = MethodInfo.GetParameters ();

				if (HasParameters) {
					_paramMap = new Dictionary<string, int> (_params.Length, StringComparer.Ordinal);
					for (int i = 0; i < _params.Length; i++)
						_paramMap.Add(_params[i].Name, i);
				}

				if (ScriptMethod.ResponseFormat == ResponseFormat.Xml
					&& MethodInfo.ReturnType != typeof (void)) {
					Type retType = MethodInfo.ReturnType;
					if (Type.GetTypeCode (retType) != TypeCode.String || ScriptMethod.XmlSerializeString)
						_xmlSer = new XmlSerializer (retType);
				}
			}
 private LogicalMethodInfo(System.Reflection.MethodInfo beginMethodInfo, System.Reflection.MethodInfo endMethodInfo, WebMethod webMethod)
 {
     this.methodInfo = beginMethodInfo;
     this.endMethodInfo = endMethodInfo;
     this.methodName = beginMethodInfo.Name.Substring(5);
     if (webMethod != null)
     {
         this.binding = webMethod.binding;
         this.attribute = webMethod.attribute;
         this.declaration = webMethod.declaration;
     }
     ParameterInfo[] parameters = beginMethodInfo.GetParameters();
     if (((parameters.Length < 2) || (parameters[parameters.Length - 1].ParameterType != typeof(object))) || (parameters[parameters.Length - 2].ParameterType != typeof(AsyncCallback)))
     {
         throw new InvalidOperationException(Res.GetString("WebMethodMissingParams", new object[] { beginMethodInfo.DeclaringType.FullName, beginMethodInfo.Name, typeof(AsyncCallback).FullName, typeof(object).FullName }));
     }
     this.stateParam = parameters[parameters.Length - 1];
     this.callbackParam = parameters[parameters.Length - 2];
     this.inParams = GetInParameters(beginMethodInfo, parameters, 0, parameters.Length - 2, true);
     ParameterInfo[] paramInfos = endMethodInfo.GetParameters();
     this.resultParam = paramInfos[0];
     this.outParams = GetOutParameters(endMethodInfo, paramInfos, 1, paramInfos.Length - 1, true);
     this.parameters = new ParameterInfo[this.inParams.Length + this.outParams.Length];
     this.inParams.CopyTo(this.parameters, 0);
     this.outParams.CopyTo(this.parameters, this.inParams.Length);
     this.retType = endMethodInfo.ReturnType;
     this.isVoid = this.retType == typeof(void);
     this.attributes = new Hashtable();
 }
 internal WebServiceMethodData(WebServiceData owner, MethodInfo methodInfo, WebMethodAttribute webMethodAttribute, ScriptMethodAttribute scriptMethodAttribute) {
     _owner = owner;
     _methodInfo = methodInfo;
     _webMethodAttribute = webMethodAttribute;
     _methodName = _webMethodAttribute.MessageName;
     _scriptMethodAttribute = scriptMethodAttribute;
     if (String.IsNullOrEmpty(_methodName)) {
         _methodName = methodInfo.Name;
     }
 }
예제 #4
0
		public void TestConstructors ()
		{
			WebMethodAttribute attribute;

			attribute = new WebMethodAttribute ();
			Assert.AreEqual (true, attribute.BufferResponse);
			Assert.AreEqual (0, attribute.CacheDuration);
			Assert.AreEqual (String.Empty, attribute.Description);
			Assert.AreEqual (false, attribute.EnableSession);
			Assert.AreEqual (String.Empty, attribute.MessageName);
			Assert.AreEqual (TransactionOption.Disabled, attribute.TransactionOption);
		}
		//
		// Constructor
		//
		public MethodStubInfo (TypeStubInfo parent, LogicalMethodInfo source)
		{
			TypeStub = parent;
			MethodInfo = source;

			object [] o = source.GetCustomAttributes (typeof (WebMethodAttribute));
			if (o.Length > 0)
			{
				MethodAttribute = (WebMethodAttribute) o [0];
				Name = MethodAttribute.MessageName;
				if (Name == "") Name = source.Name;
			}
			else
				Name = source.Name;
		}
예제 #6
0
        internal LogicalMethodInfo(MethodInfo methodInfo, WebMethod webMethod) {
            if (methodInfo.IsStatic) throw new InvalidOperationException(Res.GetString(Res.WebMethodStatic, methodInfo.Name));
            this.methodInfo = methodInfo;
            if (webMethod != null) {
                this.binding = webMethod.binding;
                this.attribute = webMethod.attribute;
                this.declaration = webMethod.declaration;
            }

            MethodInfo methodDefinition = declaration != null ? declaration : methodInfo;
            parameters = methodDefinition.GetParameters();
            inParams = GetInParameters(methodDefinition, parameters, 0, parameters.Length, false);
            outParams = GetOutParameters(methodDefinition, parameters, 0, parameters.Length, false);
            retType = methodDefinition.ReturnType;
            isVoid = retType == typeof(void);
            methodName = methodDefinition.Name;
            attributes = new Hashtable();
        }
예제 #7
0
        /*
         * internal static WebMethodAttribute GetAttribute(MethodInfo implementation) {
         *  return GetAttribute(implementation, null);
         * }
         */

        internal static WebMethodAttribute GetAttribute(MethodInfo implementation, MethodInfo declaration)
        {
            WebMethodAttribute declAttribute = null;
            WebMethodAttribute implAttribute = null;

            object[] attrs;

            if (declaration != null)
            {
                attrs = declaration.GetCustomAttributes(typeof(WebMethodAttribute), false);
                if (attrs.Length > 0)
                {
                    declAttribute = (WebMethodAttribute)attrs[0];
                }
            }
            attrs = implementation.GetCustomAttributes(typeof(WebMethodAttribute), false);
            if (attrs.Length > 0)
            {
                implAttribute = (WebMethodAttribute)attrs[0];
            }
            if (declAttribute == null)
            {
                return(implAttribute);
            }
            if (implAttribute == null)
            {
                return(declAttribute);
            }
            if (implAttribute.MessageNameSpecified)
            {
                throw new InvalidOperationException(Res.GetString(Res.ContractOverride, implementation.Name, implementation.DeclaringType.FullName, declaration.DeclaringType.FullName, declaration.ToString(), "WebMethod.MessageName"));
            }
            // merge two attributes
            WebMethodAttribute attribute = new WebMethodAttribute(implAttribute.EnableSessionSpecified ? implAttribute.EnableSession : declAttribute.EnableSession);

            attribute.TransactionOption = implAttribute.TransactionOptionSpecified ? implAttribute.TransactionOption : declAttribute.TransactionOption;
            attribute.CacheDuration     = implAttribute.CacheDurationSpecified ? implAttribute.CacheDuration : declAttribute.CacheDuration;
            attribute.BufferResponse    = implAttribute.BufferResponseSpecified ? implAttribute.BufferResponse : declAttribute.BufferResponse;
            attribute.Description       = implAttribute.DescriptionSpecified ? implAttribute.Description : declAttribute.Description;
            return(attribute);
        }
 internal LogicalMethodInfo(System.Reflection.MethodInfo methodInfo, WebMethod webMethod)
 {
     if (methodInfo.IsStatic)
     {
         throw new InvalidOperationException(Res.GetString("WebMethodStatic", new object[] { methodInfo.Name }));
     }
     this.methodInfo = methodInfo;
     if (webMethod != null)
     {
         this.binding = webMethod.binding;
         this.attribute = webMethod.attribute;
         this.declaration = webMethod.declaration;
     }
     System.Reflection.MethodInfo info = (this.declaration != null) ? this.declaration : methodInfo;
     this.parameters = info.GetParameters();
     this.inParams = GetInParameters(info, this.parameters, 0, this.parameters.Length, false);
     this.outParams = GetOutParameters(info, this.parameters, 0, this.parameters.Length, false);
     this.retType = info.ReturnType;
     this.isVoid = this.retType == typeof(void);
     this.methodName = info.Name;
     this.attributes = new Hashtable();
 }
        internal static WebMethodAttribute GetAttribute(MethodInfo implementation, MethodInfo declaration)
        {
            WebMethodAttribute attribute  = null;
            WebMethodAttribute attribute2 = null;

            object[] customAttributes;
            if (declaration != null)
            {
                customAttributes = declaration.GetCustomAttributes(typeof(WebMethodAttribute), false);
                if (customAttributes.Length > 0)
                {
                    attribute = (WebMethodAttribute)customAttributes[0];
                }
            }
            customAttributes = implementation.GetCustomAttributes(typeof(WebMethodAttribute), false);
            if (customAttributes.Length > 0)
            {
                attribute2 = (WebMethodAttribute)customAttributes[0];
            }
            if (attribute == null)
            {
                return(attribute2);
            }
            if (attribute2 == null)
            {
                return(attribute);
            }
            if (attribute2.MessageNameSpecified)
            {
                throw new InvalidOperationException(Res.GetString("ContractOverride", new object[] { implementation.Name, implementation.DeclaringType.FullName, declaration.DeclaringType.FullName, declaration.ToString(), "WebMethod.MessageName" }));
            }
            return(new WebMethodAttribute(attribute2.EnableSessionSpecified ? attribute2.EnableSession : attribute.EnableSession)
            {
                TransactionOption = attribute2.TransactionOptionSpecified ? attribute2.TransactionOption : attribute.TransactionOption, CacheDuration = attribute2.CacheDurationSpecified ? attribute2.CacheDuration : attribute.CacheDuration, BufferResponse = attribute2.BufferResponseSpecified ? attribute2.BufferResponse : attribute.BufferResponse, Description = attribute2.DescriptionSpecified ? attribute2.Description : attribute.Description
            });
        }
예제 #10
0
 internal WebMethod(MethodInfo declaration, WebServiceBindingAttribute binding, WebMethodAttribute attribute)
 {
     this.declaration = declaration;
     this.binding     = binding;
     this.attribute   = attribute;
 }
예제 #11
0
			public AsmxLogicalMethodInfo (LogicalTypeInfo typeInfo, MethodInfo method)
				: base (typeInfo, method)
			{
				_typeInfo = typeInfo;

				_wma = (WebMethodAttribute) Attribute.GetCustomAttribute (method, typeof (WebMethodAttribute));

				_sma = (ScriptMethodAttribute) Attribute.GetCustomAttribute (method, typeof (ScriptMethodAttribute));
				if (_sma == null)
					_sma = ScriptMethodAttribute.Default;

				if (ScriptMethod.ResponseFormat == ResponseFormat.Xml
					&& MethodInfo.ReturnType != typeof (void)) {
					Type retType = MethodInfo.ReturnType;
					if (Type.GetTypeCode (retType) != TypeCode.String || ScriptMethod.XmlSerializeString)
						_xmlSer = new XmlSerializer (retType);
				}
			}
        /*
        internal static WebMethodAttribute GetAttribute(MethodInfo implementation) {
            return GetAttribute(implementation, null);
        }
        */

        internal static WebMethodAttribute GetAttribute(MethodInfo implementation, MethodInfo declaration) {
            WebMethodAttribute declAttribute = null;
            WebMethodAttribute implAttribute = null;
            object[] attrs;

            if (declaration != null) {
                attrs = declaration.GetCustomAttributes(typeof(WebMethodAttribute), false);
                if (attrs.Length > 0) {
                    declAttribute = (WebMethodAttribute)attrs[0];
                }
            }
            attrs = implementation.GetCustomAttributes(typeof(WebMethodAttribute), false);
            if (attrs.Length > 0) {
                implAttribute = (WebMethodAttribute)attrs[0];
            }
            if (declAttribute == null) {
                return implAttribute;
            }
            if (implAttribute == null) {
                return declAttribute;
            }
            if (implAttribute.MessageNameSpecified) {
                throw new InvalidOperationException(Res.GetString(Res.ContractOverride, implementation.Name, implementation.DeclaringType.FullName, declaration.DeclaringType.FullName, declaration.ToString(), "WebMethod.MessageName"));
            }
            // merge two attributes
            WebMethodAttribute attribute = new WebMethodAttribute(implAttribute.EnableSessionSpecified ? implAttribute.EnableSession : declAttribute.EnableSession);
            attribute.TransactionOption = implAttribute.TransactionOptionSpecified ? implAttribute.TransactionOption : declAttribute.TransactionOption;
            attribute.CacheDuration = implAttribute.CacheDurationSpecified ? implAttribute.CacheDuration : declAttribute.CacheDuration;
            attribute.BufferResponse = implAttribute.BufferResponseSpecified ? implAttribute.BufferResponse : declAttribute.BufferResponse;
            attribute.Description = implAttribute.DescriptionSpecified ? implAttribute.Description : declAttribute.Description;
            return attribute;
        }
예제 #13
0
        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());
        }
 internal WebMethod(MethodInfo declaration, WebServiceBindingAttribute binding, WebMethodAttribute attribute) {
     this.declaration = declaration;
     this.binding = binding;
     this.attribute = attribute;
 }
예제 #15
0
        internal static LogicalMethodInfo[] GetMethods(Type type)
        {
            if (type.IsInterface)
            {
                throw new InvalidOperationException(Res.GetString(Res.NeedConcreteType, type.FullName));
            }
            ArrayList list = new ArrayList();

            MethodInfo[] methods     = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
            Hashtable    unique      = new Hashtable();
            Hashtable    methodInfos = new Hashtable();

            for (int i = 0; i < methods.Length; i++)
            {
                Type declaringType = methods[i].DeclaringType;
                if (declaringType == typeof(object))
                {
                    continue;
                }
                if (declaringType == typeof(WebService))
                {
                    continue;
                }
                string     signature               = methods[i].ToString();
                MethodInfo declaration             = FindInterfaceMethodInfo(declaringType, signature);
                WebServiceBindingAttribute binding = null;

                if (declaration != null)
                {
                    object[] attrs = declaration.DeclaringType.GetCustomAttributes(typeof(WebServiceBindingAttribute), false);
                    if (attrs.Length > 0)
                    {
                        if (attrs.Length > 1)
                        {
                            throw new ArgumentException(Res.GetString(Res.OnlyOneWebServiceBindingAttributeMayBeSpecified1, declaration.DeclaringType.FullName), "type");
                        }
                        binding = (WebServiceBindingAttribute)attrs[0];
                        if (binding.Name == null || binding.Name.Length == 0)
                        {
                            binding.Name = declaration.DeclaringType.Name;
                        }
                    }
                    else
                    {
                        declaration = null;
                    }
                }
                else if (!methods[i].IsPublic)
                {
                    continue;
                }
                WebMethodAttribute attribute = WebMethodReflector.GetAttribute(methods[i], declaration);
                if (attribute == null)
                {
                    continue;
                }

                WebMethod webMethod = new WebMethod(declaration, binding, attribute);
                methodInfos.Add(methods[i], webMethod);
                MethodInfo method = (MethodInfo)unique[signature];
                if (method == null)
                {
                    unique.Add(signature, methods[i]);
                    list.Add(methods[i]);
                }
                else
                {
                    if (method.DeclaringType.IsAssignableFrom(methods[i].DeclaringType))
                    {
                        unique[signature]          = methods[i];
                        list[list.IndexOf(method)] = methods[i];
                    }
                }
            }
            return(LogicalMethodInfo.Create((MethodInfo[])list.ToArray(typeof(MethodInfo)), LogicalMethodTypes.Async | LogicalMethodTypes.Sync, methodInfos));
        }
 void MoveToMethod(LogicalMethodInfo method) {
     this.method = method;
     this.methodAttr = method.MethodAttribute;
 }
예제 #17
0
        LogicalMethodInfo(MethodInfo beginMethodInfo, MethodInfo endMethodInfo, WebMethod webMethod) {
            this.methodInfo = beginMethodInfo;
            this.endMethodInfo = endMethodInfo;
            methodName = beginMethodInfo.Name.Substring(5);
            if (webMethod != null) {
                this.binding = webMethod.binding;
                this.attribute = webMethod.attribute;
                this.declaration = webMethod.declaration;
            }
            ParameterInfo[] beginParamInfos = beginMethodInfo.GetParameters();
            if (beginParamInfos.Length < 2 ||
                beginParamInfos[beginParamInfos.Length - 1].ParameterType != typeof(object) ||
                beginParamInfos[beginParamInfos.Length - 2].ParameterType != typeof(AsyncCallback)) {
                throw new InvalidOperationException(Res.GetString(Res.WebMethodMissingParams, beginMethodInfo.DeclaringType.FullName, beginMethodInfo.Name, 
                    typeof(AsyncCallback).FullName, typeof(object).FullName));
            }

            stateParam = beginParamInfos[beginParamInfos.Length - 1];
            callbackParam = beginParamInfos[beginParamInfos.Length - 2];

            inParams = GetInParameters(beginMethodInfo, beginParamInfos, 0, beginParamInfos.Length - 2, true);

            ParameterInfo[] endParamInfos = endMethodInfo.GetParameters();
            resultParam = endParamInfos[0];
            outParams = GetOutParameters(endMethodInfo, endParamInfos, 1, endParamInfos.Length - 1, true);

            parameters = new ParameterInfo[inParams.Length + outParams.Length];
            inParams.CopyTo(parameters, 0);
            outParams.CopyTo(parameters, inParams.Length);

            retType = endMethodInfo.ReturnType;
            isVoid = retType == typeof(void);
            attributes = new Hashtable();
        }
        internal static LogicalMethodInfo[] GetMethods(Type type)
        {
            if (type.IsInterface)
            {
                throw new InvalidOperationException(Res.GetString("NeedConcreteType", new object[] { type.FullName }));
            }
            ArrayList list = new ArrayList();

            MethodInfo[] methods      = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
            Hashtable    hashtable    = new Hashtable();
            Hashtable    declarations = new Hashtable();

            for (int i = 0; i < methods.Length; i++)
            {
                Type declaringType = methods[i].DeclaringType;
                if ((declaringType != typeof(object)) && (declaringType != typeof(WebService)))
                {
                    string     signature               = methods[i].ToString();
                    MethodInfo declaration             = FindInterfaceMethodInfo(declaringType, signature);
                    WebServiceBindingAttribute binding = null;
                    if (declaration != null)
                    {
                        object[] customAttributes = declaration.DeclaringType.GetCustomAttributes(typeof(WebServiceBindingAttribute), false);
                        if (customAttributes.Length > 0)
                        {
                            if (customAttributes.Length > 1)
                            {
                                throw new ArgumentException(Res.GetString("OnlyOneWebServiceBindingAttributeMayBeSpecified1", new object[] { declaration.DeclaringType.FullName }), "type");
                            }
                            binding = (WebServiceBindingAttribute)customAttributes[0];
                            if ((binding.Name == null) || (binding.Name.Length == 0))
                            {
                                binding.Name = declaration.DeclaringType.Name;
                            }
                        }
                        else
                        {
                            declaration = null;
                        }
                    }
                    else if (!methods[i].IsPublic)
                    {
                        continue;
                    }
                    WebMethodAttribute attribute = GetAttribute(methods[i], declaration);
                    if (attribute != null)
                    {
                        WebMethod method = new WebMethod(declaration, binding, attribute);
                        declarations.Add(methods[i], method);
                        MethodInfo info2 = (MethodInfo)hashtable[signature];
                        if (info2 == null)
                        {
                            hashtable.Add(signature, methods[i]);
                            list.Add(methods[i]);
                        }
                        else if (info2.DeclaringType.IsAssignableFrom(methods[i].DeclaringType))
                        {
                            hashtable[signature]      = methods[i];
                            list[list.IndexOf(info2)] = methods[i];
                        }
                    }
                }
            }
            return(LogicalMethodInfo.Create((MethodInfo[])list.ToArray(typeof(MethodInfo)), LogicalMethodTypes.Async | LogicalMethodTypes.Sync, declarations));
        }