Discussion:
Dynamic Method Call
(too old to reply)
R3al1ty
2008-06-18 05:59:16 UTC
Permalink
Hi folks,

I have hundreds of methods exposed on the app server via remoting. Is
there a way for a client to dynamically invoke any one of these
methods if I know the class name, method name and have a string
containing the serialized objects to be passed as the method params? I
would also like to retrieve the object the method returned, as a
serialized string.

Thanks.
Jeff Winn
2008-06-22 19:10:00 UTC
Permalink
Well, create a remoted object that takes the class, method, and the string
array containing the arguments. You can use the activator class to create an
instance of the object that you needed it to create, and use reflection on
that object to invoke the method.

As for the return, you could use the XmlSerializer to serialize the object
being returned as a string.
Post by R3al1ty
Hi folks,
I have hundreds of methods exposed on the app server via remoting. Is
there a way for a client to dynamically invoke any one of these
methods if I know the class name, method name and have a string
containing the serialized objects to be passed as the method params? I
would also like to retrieve the object the method returned, as a
serialized string.
Thanks.
R3al1ty
2008-06-23 08:46:31 UTC
Permalink
Sorry, I should have been more detailed. Performance is a key concern,
which is why we did not want to use Reflection. On those lines, how
expensive is even the Remoting part of things when it creates a remote
object?

Thanks
Jeff Winn
2008-06-23 22:50:54 UTC
Permalink
You have no choice in the matter whether you want to use reflection to
invoke the method. The objects themselves I'm not sure how much more
overhead is required for the objects when they're remoted, never bothered to
look. When I need to remote something, I just do it.

If you're worried about performance with Reflection, cache the MethodInfo
instances for the type in a collection (as an example I'd probably use a
dictionary with the name of the method being the key). However if you're
also remoting overloads you'll need to add more data to the key to ensure
they're kept unique. Performance on the remoting side of things depends on
the type of remoting you're using for an object. Single call is going to
reduce performance a lot more than singleton would. It really all depends on
what your application is needing.
Post by R3al1ty
Sorry, I should have been more detailed. Performance is a key concern,
which is why we did not want to use Reflection. On those lines, how
expensive is even the Remoting part of things when it creates a remote
object?
Thanks
R3al1ty
2008-06-25 07:04:36 UTC
Permalink
I'll keep these points in mind, thanks!
Jeff Winn
2008-06-26 05:06:57 UTC
Permalink
Not a problem, good luck with your project :o)
Post by R3al1ty
I'll keep these points in mind, thanks!
Loading...