Calling a method sent as a parameter RRS feed

  • Question

  • User359834357 posted

    Below is some code I use it to call different methods in a web service. Each method has different parameters and return types, and I just wanted a generic method that I could call for all of them.
    More importantly, for every call to the service, I needed to do some further processing to check if the ticket used to identify my call to the service) was expired. If I didn't have a generic method like this, I would need to implement the check with every call:
        public static object CallService(string ServiceMethod, object[] ServiceMethodParams)
            object Result = null;

            System.Reflection.MethodInfo mi = MyService.GetType().GetMethod(ServiceMethod);

            Result = mi.Invoke(MyService, ServiceMethodParams);

            // If the request comes back with a "Ticket expired" header, re-login and attempt to call the method again
            if (MyService.TicketHeaderValue.Expired == 1)
                Result = mi.Invoke(MyService, ServiceMethodParams);

            return Result;

    Monday, June 15, 2009 6:26 AM

All replies

  • User-1110131619 posted

    Ok...what is your problem?  You have asked no questions. 

    Monday, December 14, 2009 8:56 AM
  • User-1360095595 posted

    I don't think he has a problem.  This is the Tips & Tricks section.  People share, well, their Tips & Tricks so others may benefit from them.

    Monday, December 14, 2009 8:59 AM
  • User359834357 posted


    Monday, December 14, 2009 9:01 AM