public override IMessage Invoke(IMessage reqMsg)
{
// Dispatch based on whether its a constructor call
// or a method call
IConstructionCallMessage ccm = reqMsg as IConstructionCallMessage;
if(ccm != null)
{
// Activate
return InternalActivate(ccm);
}
else
{
// Handle regular method calls
// Check that the initialization has completed
if(!Initialized)
{
// This covers the case where an object may call out
// on another object passing its "this" pointer during its
// .ctor.
// The other object attempting to call on the this pointer
// (in x-context case) would be calling on a proxy not
// marked fully initialized.
// Let the original constructor thread go through but
// throw for other threads.
if (CtorThread == Thread.CurrentThread.GetHashCode())
{
ServerIdentity srvId = IdentityObject as ServerIdentity;
BCLDebug.Assert(
srvId != null
&&
((ServerIdentity)IdentityObject).ServerContext != null,
"Wrap may associate with wrong context!");
// If we are here, the server object passed itself
// out to another x-context object during the .ctor
// That guy is calling us back. Let us call Wrap()
// earlier than usual so that envoy & channel sinks
// get set up!
RemotingServices.Wrap(
(ContextBoundObject) this.UnwrappedServerObject);
}
else
{
// Throw an exception to indicate that we are
// calling on a proxy while the constructor call
// is still running.
throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_InvalidCall"));
}
}
// Dispatch
int callType = Message.Sync;
Message msg = reqMsg as Message;
if (msg != null)
{
callType = msg.GetCallType();
}
return InternalInvoke((IMethodCallMessage)reqMsg, false, callType);
}
} // Invoke