是否可以通过反射获取调用方法类的实例,或调用堆栈中的任何方法?
是否可以使用反射来获取调用方法的类的实例?
尝试“破解”Web 服务的解决方案以传递传入呼叫的超时值(当您调用 Web 服务,而该 Web 服务又使用 WSE 调用新的 Web 服务时。当客户端设置 5 分钟的超时和下一个级别时,这很糟糕只有默认值 100 秒,反之亦然。)。
我已经有了一个自定义策略,一旦代理实例调用 .SetProxy(...),就会调用该策略。这是我想要访问的实例,但我可以开始编码的策略代码是下面的 3 个“级别”。
所以我想知道如果我执行 2 个级别的 stacktrace getmethod,我是否能够以任何方式获取该实例?到目前为止,我只能获取该类的类型,而不能获取实例。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对华尔街英语不熟悉,但对反思很了解。要获取实例,您需要具有其引用或对引用的引用的东西。如果您可以找到任何将调用对象作为引用的类,请使用 Reflection.GetField、Reflection.GetProperty 和/或 Reflection.GetMethod 来获取该值。即使要穿过五层保护区,只要你能走到那里,就能找到它。但是,如果它是一个彻底的中断,例如不同线程或 exe 的生成,并且没有传递任何识别信息,那么您就不走运了。您必须使用外部源来存储所需的超时,然后让呼叫的每一方引用它。使用 Red Gate .Net Reflector 查看类以供参考。
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.