views:

109

answers:

1

Is it possible using reflection to get THE instance of the class of a calling method?

Trying to "hack" a solution for webservices to pass on the Timeout value of the incoming call (When you call a webservice that in turn calls a new webservice using WSE. It sucks when the client sets a timeout of 5 mins and the next level only have the default of 100seconds, or the other way around.).

I already got a custom policy that gets called once the proxy instance calls .SetProxy(...). This is the instance I want to get access to, but the policy code where I can start coding this is 3 "levels" below.

So I am wondering if I do a stacktrace getmethod up 2 levels, will I be able to get that instance in any way? So far I have only been able to get the Type of that class and not the instance.

A: 

I am not familiar with WSE but know reflection quite well. To get the instance, you need something that has its reference or a reference to a reference. If you can find any class that has the calling object as a reference, use Reflection.GetField, Reflection.GetProperty, and/or Reflection.GetMethod to get to the value. Even if it means going through 5 layers with protected fields, as long as you can step there you can find it. But if it is a clean break, like a spawn of a different thread or exe, and no identifying information is passed through, then you are out of luck. You will have to use an external source to store the timeout needed and then have each side of the call reference it. Use Red Gate .Net Reflector to look at the classes for the reference.

JDMX
i dont see an instance. do you?
Sky Sanders
The MethodBase is still just information about the method that called, is it not? I am looking for a way to grab the instance of a method in the stacktrace. Not a new one, but the actual instance that called. I am not sure if it is really possible, and is why I am asking here.
Wolf5