In the code behind for each page, how can I use reflection to get all the webmethods I have defined on that page?
Currently I have the following and call it in the Page_Load() but it doesn’t find my 1 static function that I have a webmethod attribute on.
MethodInfo[] methods = this.GetType().GetMethods();
foreach (MethodInfo method in methods)
{
foreach (Attribute attribute in method.GetCustomAttributes(true))
{
if (attribute is WebMethodAttribute)
{
}
}
}
Try this for Public static :
Works for me