private void PrivateInvoke(ref MessageData msgData, int type)
{
IMessage reqMsg = null;
CallType type2 = (CallType) type;
IMessage retMsg = null;
int msgFlags = -1;
RemotingProxy proxy = null;
if (CallType.MethodCall == type2)
{
Message message3 = new Message();
message3.InitFields(msgData);
reqMsg = message3;
msgFlags = message3.GetCallType();
}
else if (CallType.ConstructorCall == type2)
{
msgFlags = 0;
proxy = this as RemotingProxy;
ConstructorCallMessage ccm = null;
bool flag = false;
if (!this.IsRemotingProxy())
{
ccm = new ConstructorCallMessage(null, null, null, (RuntimeType) this.GetProxiedType());
}
else
{
ccm = proxy.ConstructorMessage;
Identity identityObject = proxy.IdentityObject;
if (identityObject != null)
{
flag = identityObject.IsWellKnown();
}
}
if ((ccm == null) || flag)
{
ccm = new ConstructorCallMessage(null, null, null, (RuntimeType) this.GetProxiedType());
ccm.SetFrame(msgData);
reqMsg = ccm;
if (flag)
{
proxy.ConstructorMessage = null;
if (ccm.ArgCount != 0)
{
throw new RemotingException(Environment.GetResourceString("Remoting_Activation_WellKnownCTOR"));
}
}
retMsg = new ConstructorReturnMessage((MarshalByRefObject) this.GetTransparentProxy(), null, 0, null, ccm);
}
else
{
ccm.SetFrame(msgData);
reqMsg = ccm;
}
}
ChannelServices.IncrementRemoteCalls();
if (!this.IsRemotingProxy() && ((msgFlags & 2) == 2))
{
Message message5 = reqMsg as Message;
retMsg = EndInvokeHelper(message5, true);
}
if (retMsg == null)
{
LogicalCallContext cctx = null;
Thread currentThread = Thread.CurrentThread;
cctx = currentThread.GetLogicalCallContext();
this.SetCallContextInMessage(reqMsg, msgFlags, cctx);
cctx.PropagateOutgoingHeadersToMessage(reqMsg);
retMsg = this.Invoke(reqMsg);
this.ReturnCallContextToThread(currentThread, retMsg, msgFlags, cctx);
CallContext.GetLogicalCallContext().PropagateIncomingHeadersToCallContext(retMsg);
}
if (!this.IsRemotingProxy() && ((msgFlags & 1) == 1))
{
Message m = reqMsg as Message;
AsyncResult ret = new AsyncResult(m);
ret.SyncProcessMessage(retMsg);
retMsg = new ReturnMessage(ret, null, 0, null, m);
}
HandleReturnMessage(reqMsg, retMsg);
if (CallType.ConstructorCall == type2)
{
MarshalByRefObject obj2 = null;
IConstructionReturnMessage message7 = retMsg as IConstructionReturnMessage;
if (message7 == null)
{
throw new RemotingException(Environment.GetResourceString("Remoting_Proxy_BadReturnTypeForActivation"));
}
ConstructorReturnMessage message8 = message7 as ConstructorReturnMessage;
if (message8 != null)
{
obj2 = (MarshalByRefObject) message8.GetObject();
if (obj2 == null)
{
throw new RemotingException(Environment.GetResourceString("Remoting_Activation_NullReturnValue"));
}
}
else
{
obj2 = (MarshalByRefObject) RemotingServices.InternalUnmarshal((ObjRef) message7.ReturnValue, this.GetTransparentProxy(), true);
if (obj2 == null)
{
throw new RemotingException(Environment.GetResourceString("Remoting_Activation_NullFromInternalUnmarshal"));
}
}
if (obj2 != ((MarshalByRefObject) this.GetTransparentProxy()))
{
throw new RemotingException(Environment.GetResourceString("Remoting_Activation_InconsistentState"));
}
if (this.IsRemotingProxy())
{
proxy.ConstructorMessage = null;
}
}
}