locked
How do you get the value of Webmethod Attributes? RRS feed

  • Question

  • Hello, I'm trying to obtain the value of MessageName or Description property of my webmethod:

    example, I define the webmethod like this:

     <WebMethod(Description:="Overload Method, Accepts App ProcID as string")> 
    Inside the method itself I want to get the value of the description in order to log the call to this method.

    Wednesday, June 6, 2012 4:47 PM

Answers

  • You can use reflection.

                System.Reflection.MethodBase methodBase = System.Reflection.MethodInfo.GetCurrentMethod();
                object[] methodAttributes = methodBase.GetCustomAttributes(false);

    • Marked as answer by Nezoic Wednesday, June 6, 2012 7:54 PM
    Wednesday, June 6, 2012 6:26 PM

All replies

  • You can use reflection.

                System.Reflection.MethodBase methodBase = System.Reflection.MethodInfo.GetCurrentMethod();
                object[] methodAttributes = methodBase.GetCustomAttributes(false);

    • Marked as answer by Nezoic Wednesday, June 6, 2012 7:54 PM
    Wednesday, June 6, 2012 6:26 PM
  • Perfect, thank you Adnan!
    Wednesday, June 6, 2012 7:54 PM