Thursday, April 14, 2011

Verify that a method is called via remoting?

How can I, from within a method, verify that it executes inside a remoting context? I've got a basic Client -> NT-Service setup where the service executes as a specific user. This user has access to a SQL Server.

I am looking for a solution that would make it easier to catch problems that occur when the remoting configuration is missing or bad (a method that wasn't specified, etc). I would like to be able to fail with a better error message ("This method requires a remoting context to work properly.") instead of failing with login errors. It's even more tricky when the original user has readonly access to the database and the error isn't thrown until data is written.

From stackoverflow
  • I like using the MS enterprise Library for debugging purposes, you can try using the logging and the exception handling blocks to handle the error.

    Simon Svensson : I am not looking for ways to handle the error, but to detect if I am inside a remoting context.
  • Well, you could use use the stacktrace class in System.Diagnostics to check where the method call is coming from. :)

    Mark : Note that walking the stack isn't without performance implications.

0 comments:

Post a Comment