private void SerializeContextElements(CdrOutputStream targetStream, LogicalCallContext callContext, Serializer contextElementSer) { // if no context elements specified, don't serialise a context sequence. if (m_contextElementKeys.Length > 0) { string[] contextSeq = new string[m_contextElementKeys.Length * 2]; for (int i = 0; i < m_contextElementKeys.Length; i++) { string contextKey = m_contextElementKeys[i]; contextSeq[i * 2] = contextKey; if (callContext.GetData(contextKey) != null) { contextSeq[i * 2 + 1] = callContext.GetData(contextKey).ToString(); } else { contextSeq[i * 2 + 1] = ""; } } contextElementSer.Serialize(contextSeq, targetStream); } }
public Object GetData(String name) { return(IsNull ? null : m_ctx.GetData(name)); }
[System.Security.SecurityCritical] // auto-generated internal virtual IMessage SyncProcessMessage(IMessage msg, int methodPtr, bool fExecuteInContext) { // Validate message here IMessage errMsg = InternalSink.ValidateMessage(msg); if (errMsg != null) { return(errMsg); } IMethodCallMessage mcMsg = msg as IMethodCallMessage; IMessage retMessage; LogicalCallContext oldCallCtx = null; LogicalCallContext lcc = CallContext.GetLogicalCallContext(); object xADCall = lcc.GetData(CrossAppDomainSink.LCC_DATA_KEY); bool isCallContextSet = false; try { Object server = _server; BCLDebug.Assert((server != null) == (!_bStatic), "Invalid state in stackbuilder sink?"); // validate the method base if necessary VerifyIsOkToCallMethod(server, mcMsg); // install call context onto the thread, holding onto // the one that is currently on the thread LogicalCallContext messageCallContext = null; if (mcMsg != null) { messageCallContext = mcMsg.LogicalCallContext; } else { messageCallContext = (LogicalCallContext)msg.Properties["__CallContext"]; } oldCallCtx = CallContext.SetLogicalCallContext(messageCallContext); isCallContextSet = true; messageCallContext.PropagateIncomingHeadersToCallContext(msg); PreserveThreadPrincipalIfNecessary(messageCallContext, oldCallCtx); // NOTE: target for dispatch will be NULL when the StackBuilderSink // is used for async delegates on static methods. // *** NOTE *** // Although we always pass _server to these calls in the EE, // when we execute using Message::Dispatch we are using TP as // the this-ptr ... (what the call site thinks is the this-ptr) // when we execute using StackBuilderSink::PrivatePM we use // _server as the this-ptr (which could be different if there // is interception for strictly MBR types in the same AD). // ************ if (IsOKToStackBlt(mcMsg, server) && ((Message)mcMsg).Dispatch(server, fExecuteInContext)) { //retMessage = StackBasedReturnMessage.GetObjectFromPool((Message)mcMsg); retMessage = new StackBasedReturnMessage(); ((StackBasedReturnMessage)retMessage).InitFields((Message)mcMsg); // call context could be different then the one from before the call. LogicalCallContext latestCallContext = CallContext.GetLogicalCallContext(); // retrieve outgoing response headers latestCallContext.PropagateOutgoingHeadersToMessage(retMessage); // Install call context back into Message (from the thread) ((StackBasedReturnMessage)retMessage).SetLogicalCallContext(latestCallContext); } else { MethodBase mb = GetMethodBase(mcMsg); Object[] outArgs = null; Object ret = null; RemotingMethodCachedData methodCache = InternalRemotingServices.GetReflectionCachedData(mb); Message.DebugOut("StackBuilderSink::Calling PrivateProcessMessage\n"); Object[] args = Message.CoerceArgs(mcMsg, methodCache.Parameters); ret = PrivateProcessMessage( mb.MethodHandle, args, server, methodPtr, fExecuteInContext, out outArgs); CopyNonByrefOutArgsFromOriginalArgs(methodCache, args, ref outArgs); // call context could be different then the one from before the call. LogicalCallContext latestCallContext = CallContext.GetLogicalCallContext(); if (xADCall != null && ((bool)xADCall) == true && latestCallContext != null) { // Special case Principal since if might not be serializable before returning // ReturnMessage latestCallContext.RemovePrincipalIfNotSerializable(); } retMessage = new ReturnMessage( ret, outArgs, (outArgs == null ? 0 : outArgs.Length), latestCallContext, mcMsg); // retrieve outgoing response headers latestCallContext.PropagateOutgoingHeadersToMessage(retMessage); // restore the call context on the thread CallContext.SetLogicalCallContext(oldCallCtx); } } catch (Exception e) { Message.DebugOut( "StackBuilderSink::The server object probably threw an exception " + e.Message + e.StackTrace + "\n"); retMessage = new ReturnMessage(e, mcMsg); ((ReturnMessage)retMessage).SetLogicalCallContext(mcMsg.LogicalCallContext); if (isCallContextSet) { CallContext.SetLogicalCallContext(oldCallCtx); } } return(retMessage); }
/*========================================================================= ** Get data on the logical call context ** =========================================================================*/ private static Object LogicalGetData(String name) { LogicalCallContext lcc = Thread.CurrentThread.GetLogicalCallContext(); return(lcc.GetData(name)); }
public virtual IMessage SyncProcessMessage(IMessage msg) { IMessage message = InternalSink.ValidateMessage(msg); if (message != null) { return(message); } IMethodCallMessage methodCallMessage = msg as IMethodCallMessage; LogicalCallContext logicalCallContext = null; LogicalCallContext logicalCallContext2 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext; object data = logicalCallContext2.GetData("__xADCall"); bool flag = false; IMessage message2; try { object server = this._server; StackBuilderSink.VerifyIsOkToCallMethod(server, methodCallMessage); LogicalCallContext logicalCallContext3; if (methodCallMessage != null) { logicalCallContext3 = methodCallMessage.LogicalCallContext; } else { logicalCallContext3 = (LogicalCallContext)msg.Properties["__CallContext"]; } logicalCallContext = CallContext.SetLogicalCallContext(logicalCallContext3); flag = true; logicalCallContext3.PropagateIncomingHeadersToCallContext(msg); StackBuilderSink.PreserveThreadPrincipalIfNecessary(logicalCallContext3, logicalCallContext); if (this.IsOKToStackBlt(methodCallMessage, server) && ((Message)methodCallMessage).Dispatch(server)) { message2 = new StackBasedReturnMessage(); ((StackBasedReturnMessage)message2).InitFields((Message)methodCallMessage); LogicalCallContext logicalCallContext4 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext; logicalCallContext4.PropagateOutgoingHeadersToMessage(message2); ((StackBasedReturnMessage)message2).SetLogicalCallContext(logicalCallContext4); } else { MethodBase methodBase = StackBuilderSink.GetMethodBase(methodCallMessage); object[] array = null; RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase); object[] args = Message.CoerceArgs(methodCallMessage, reflectionCachedData.Parameters); object ret = this.PrivateProcessMessage(methodBase.MethodHandle, args, server, out array); this.CopyNonByrefOutArgsFromOriginalArgs(reflectionCachedData, args, ref array); LogicalCallContext logicalCallContext5 = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext; if (data != null && (bool)data && logicalCallContext5 != null) { logicalCallContext5.RemovePrincipalIfNotSerializable(); } message2 = new ReturnMessage(ret, array, (array == null) ? 0 : array.Length, logicalCallContext5, methodCallMessage); logicalCallContext5.PropagateOutgoingHeadersToMessage(message2); CallContext.SetLogicalCallContext(logicalCallContext); } } catch (Exception e) { message2 = new ReturnMessage(e, methodCallMessage); ((ReturnMessage)message2).SetLogicalCallContext(methodCallMessage.LogicalCallContext); if (flag) { CallContext.SetLogicalCallContext(logicalCallContext); } } return(message2); }