I have a MarshalByReferenceObject
, whose methods are called via .net remoting.
public class MyServer : MarshalByReferenceObject
{
public void DoSomething();
}
System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(
typeof(MyServer), "serverUrl", System.Runtime.Remoting.WellKnownObjectMode.SingleCall);
The clients are calling the server like this:
var server = Activator.GetObject(typeof(MyServer), "serverUrl");
server.DoSomething();
Now for debugging purposes, when a client calls the DoSomething() method, I want to log who the actual caller is.
How can I identify the calling method from within my server.DoSomething() function? Or from within my server constructor, which is called by Activator.GetObject?
Ideally I would want the whole stacktrace: which client method called the server, which parent method called that client method, and so on. But I would settle for some sort of caller identification. I control the clients, so perhaps I could give them names somehow? The interface specification is already pretty much fixed, so adding an otherwise superfluous string callerId
parameter to each and every method is something I would like to avoid.
The local stack trace of course only identifies the System.Runtime.Remoting
methods, not the actual remote caller.
example stacktrace on the server side:
at MyServer.MyServer(), line 123
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
[...]
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
This obviously does not help me identify the calling method from the client.