public virtual IMessage SyncProcessMessage(IMessage reqMsg) { object[] args = new object[2]; IMessage message1; try { IMessage message2 = InternalSink.ValidateMessage(reqMsg); if (message2 != null) { return(message2); } ServerIdentity serverIdentity = InternalSink.GetServerIdentity(reqMsg); args[0] = (object)reqMsg; args[1] = (object)serverIdentity.ServerContext; message1 = (IMessage)Thread.CurrentThread.InternalCrossContextCallback(serverIdentity.ServerContext, CrossContextChannel.s_xctxDel, args); } catch (Exception ex) { IMethodCallMessage mcm = (IMethodCallMessage)reqMsg; message1 = (IMessage) new ReturnMessage(ex, mcm); if (reqMsg != null) { ((ReturnMessage)message1).SetLogicalCallContext((LogicalCallContext)reqMsg.Properties[(object)Message.CallContextKey]); } } return(message1); }
} // CreateServerChannelSinkChain // Check if the object has been disconnected or if it is // a well known object then we have to create it lazily. internal static ServerIdentity CheckDisconnectedOrCreateWellKnownObject(IMessage msg) { ServerIdentity ident = InternalSink.GetServerIdentity(msg); BCLDebug.Trace("REMOTE", "Identity found = " + (ident == null ? "null" : "ServerIdentity")); // If the identity is null, then we should check whether the // request if for a well known object. If yes, then we should // create the well known object lazily and marshal it. if ((ident == null) || ident.IsRemoteDisconnected()) { String uri = InternalSink.GetURI(msg); BCLDebug.Trace("REMOTE", "URI " + uri); if (uri != null) { ServerIdentity newIdent = RemotingConfigHandler.CreateWellKnownObject(uri); if (newIdent != null) { // The uri was a registered wellknown object. ident = newIdent; BCLDebug.Trace("REMOTE", "Identity created = " + (ident == null ? "null" : "ServerIdentity")); } } } if ((ident == null) || (ident.IsRemoteDisconnected())) { String uri = InternalSink.GetURI(msg); throw new RemotingException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Disconnected"), uri)); } return(ident); }
internal static IMessageCtrl DoAsyncDispatch(IMessage reqMsg, IMessageSink replySink) { object[] args = new object[4]; ServerIdentity serverIdentity = InternalSink.GetServerIdentity(reqMsg); if (RemotingServices.CORProfilerTrackRemotingAsync()) { Guid id = Guid.Empty; if (RemotingServices.CORProfilerTrackRemotingCookie()) { object obj = reqMsg.Properties[(object)"CORProfilerCookie"]; if (obj != null) { id = (Guid)obj; } } RemotingServices.CORProfilerRemotingServerReceivingMessage(id, true); if (replySink != null) { replySink = (IMessageSink) new ServerAsyncReplyTerminatorSink(replySink); } } Context serverContext = serverIdentity.ServerContext; args[0] = (object)reqMsg; args[1] = (object)replySink; args[2] = (object)Thread.CurrentContext; args[3] = (object)serverContext; InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(CrossContextChannel.DoAsyncDispatchCallback); return((IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(serverContext, ftnToCall, args)); }
internal static ServerIdentity CheckDisconnectedOrCreateWellKnownObject(IMessage msg) { ServerIdentity serverIdentity = InternalSink.GetServerIdentity(msg); if (serverIdentity == null || serverIdentity.IsRemoteDisconnected()) { string uri = InternalSink.GetURI(msg); if (uri != null) { ServerIdentity serverIdentity2 = RemotingConfigHandler.CreateWellKnownObject(uri); if (serverIdentity2 != null) { serverIdentity = serverIdentity2; } } } if (serverIdentity == null || serverIdentity.IsRemoteDisconnected()) { string uri2 = InternalSink.GetURI(msg); throw new RemotingException(Environment.GetResourceString("Remoting_Disconnected", new object[] { uri2 })); } return(serverIdentity); }
public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink) { IMessage msg = InternalSink.ValidateMessage(reqMsg); object[] args = new object[4]; IMessageCtrl ctrl = null; if (msg != null) { if (replySink != null) { replySink.SyncProcessMessage(msg); } return(ctrl); } ServerIdentity serverIdentity = InternalSink.GetServerIdentity(reqMsg); if (RemotingServices.CORProfilerTrackRemotingAsync()) { Guid empty = Guid.Empty; if (RemotingServices.CORProfilerTrackRemotingCookie()) { object obj2 = reqMsg.Properties["CORProfilerCookie"]; if (obj2 != null) { empty = (Guid)obj2; } } RemotingServices.CORProfilerRemotingServerReceivingMessage(empty, true); if (replySink != null) { IMessageSink sink = new ServerAsyncReplyTerminatorSink(replySink); replySink = sink; } } Context serverContext = serverIdentity.ServerContext; if (serverContext.IsThreadPoolAware) { args[0] = reqMsg; args[1] = replySink; args[2] = Thread.CurrentContext; args[3] = serverContext; InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(CrossContextChannel.AsyncProcessMessageCallback); return((IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(serverContext, ftnToCall, args)); } AsyncWorkItem item = null; item = new AsyncWorkItem(reqMsg, replySink, Thread.CurrentContext, serverIdentity); WaitCallback callBack = new WaitCallback(item.FinishAsyncWork); ThreadPool.QueueUserWorkItem(callBack); return(ctrl); }
public virtual IMessageCtrl AsyncProcessMessage(IMessage reqMsg, IMessageSink replySink) { IMessage message = InternalSink.ValidateMessage(reqMsg); object[] array = new object[4]; IMessageCtrl result = null; if (message != null) { if (replySink != null) { replySink.SyncProcessMessage(message); } } else { ServerIdentity serverIdentity = InternalSink.GetServerIdentity(reqMsg); if (RemotingServices.CORProfilerTrackRemotingAsync()) { Guid id = Guid.Empty; if (RemotingServices.CORProfilerTrackRemotingCookie()) { object obj = reqMsg.Properties["CORProfilerCookie"]; if (obj != null) { id = (Guid)obj; } } RemotingServices.CORProfilerRemotingServerReceivingMessage(id, true); if (replySink != null) { IMessageSink messageSink = new ServerAsyncReplyTerminatorSink(replySink); replySink = messageSink; } } Context serverContext = serverIdentity.ServerContext; if (serverContext.IsThreadPoolAware) { array[0] = reqMsg; array[1] = replySink; array[2] = Thread.CurrentContext; array[3] = serverContext; InternalCrossContextDelegate ftnToCall = new InternalCrossContextDelegate(CrossContextChannel.AsyncProcessMessageCallback); result = (IMessageCtrl)Thread.CurrentThread.InternalCrossContextCallback(serverContext, ftnToCall, array); } else { AsyncWorkItem @object = new AsyncWorkItem(reqMsg, replySink, Thread.CurrentContext, serverIdentity); WaitCallback callBack = new WaitCallback(@object.FinishAsyncWork); ThreadPool.QueueUserWorkItem(callBack); } } return(result); }
internal ReadOnlyCollection <TestCase> DiscoverTests(string assemblyPath, string testCaseFilter = null) { var unitTestDiscoverer = new UnitTestDiscoverer(); var logger = new InternalLogger(); var sink = new InternalSink(); string runSettingXml = this.GetRunSettingXml(string.Empty, this.GetTestAdapterPath()); var context = new InternalDiscoveryContext(runSettingXml, testCaseFilter); unitTestDiscoverer.DiscoverTestsInSource(assemblyPath, logger, sink, context); return(sink.DiscoveredTests); }
private static Sink Sink(Stream @out, Timeout timeout) { if (@out == null) { throw new ArgumentException("out == null"); } if (timeout == null) { throw new ArgumentException("timeout == null"); } var internalSink = new InternalSink(@out, timeout); return(internalSink); }
public virtual IMessage SyncProcessMessage(IMessage reqMsg) { IMessage message = InternalSink.ValidateMessage(reqMsg); if (message != null) { return(message); } IPrincipal principal = null; IMessage message2 = null; try { IMethodCallMessage methodCallMessage = reqMsg as IMethodCallMessage; if (methodCallMessage != null) { LogicalCallContext logicalCallContext = methodCallMessage.LogicalCallContext; if (logicalCallContext != null) { principal = logicalCallContext.RemovePrincipalIfNotSerializable(); } } MemoryStream memoryStream = null; SmuggledMethodCallMessage smuggledMethodCallMessage = SmuggledMethodCallMessage.SmuggleIfPossible(reqMsg); if (smuggledMethodCallMessage == null) { memoryStream = CrossAppDomainSerializer.SerializeMessage(reqMsg); } LogicalCallContext logicalCallContext2 = CallContext.SetLogicalCallContext(null); byte[] array = null; SmuggledMethodReturnMessage smuggledMethodReturnMessage; try { if (smuggledMethodCallMessage != null) { array = this.DoTransitionDispatch(null, smuggledMethodCallMessage, out smuggledMethodReturnMessage); } else { array = this.DoTransitionDispatch(memoryStream.GetBuffer(), null, out smuggledMethodReturnMessage); } } finally { CallContext.SetLogicalCallContext(logicalCallContext2); } if (smuggledMethodReturnMessage != null) { ArrayList deserializedArgs = smuggledMethodReturnMessage.FixupForNewAppDomain(); message2 = new MethodResponse((IMethodCallMessage)reqMsg, smuggledMethodReturnMessage, deserializedArgs); } else if (array != null) { MemoryStream stm = new MemoryStream(array); message2 = CrossAppDomainSerializer.DeserializeMessage(stm, reqMsg as IMethodCallMessage); } } catch (Exception e) { try { message2 = new ReturnMessage(e, reqMsg as IMethodCallMessage); } catch (Exception) { } } if (principal != null) { IMethodReturnMessage methodReturnMessage = message2 as IMethodReturnMessage; if (methodReturnMessage != null) { LogicalCallContext logicalCallContext3 = methodReturnMessage.LogicalCallContext; logicalCallContext3.Principal = principal; } } return(message2); }
public static ServerProcessing DispatchMessage( IServerChannelSinkStack sinkStack, IMessage msg, out IMessage replyMsg) { ServerProcessing processing = ServerProcessing.Complete; replyMsg = null; try { if (null == msg) { throw new ArgumentNullException("msg"); } BCLDebug.Trace("REMOTE", "Dispatching for URI " + InternalSink.GetURI(msg)); // we must switch to the target context of the object and call the context chains etc... // Currenly XContextChannel does exactly so. So this method is just a wrapper.. // Make sure that incoming calls are counted as a remote call. This way it // makes more sense on a server. IncrementRemoteCalls(); // Check if the object has been disconnected or if it is // a well known object then we have to create it lazily. ServerIdentity srvId = CheckDisconnectedOrCreateWellKnownObject(msg); // Make sure that this isn't an AppDomain object since we don't allow // calls to the AppDomain from out of process (and x-process calls // are always dispatched through this method) if (srvId.ServerType == typeof(System.AppDomain)) { throw new RemotingException( Environment.GetResourceString( "Remoting_AppDomainsCantBeCalledRemotely")); } IMethodCallMessage mcm = msg as IMethodCallMessage; if (mcm == null) { // It's a plain IMessage, so just check to make sure that the // target object implements IMessageSink and dispatch synchronously. if (!typeof(IMessageSink).IsAssignableFrom(srvId.ServerType)) { throw new RemotingException( Environment.GetResourceString( "Remoting_AppDomainsCantBeCalledRemotely")); } processing = ServerProcessing.Complete; replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg); } else { // It's an IMethodCallMessage. // Check if the method is one way. Dispatch one way calls in // an asynchronous manner MethodInfo method = (MethodInfo)mcm.MethodBase; // X-process / X-machine calls should be to non-static // public methods only! Non-public or static methods can't // be called remotely. if (!IsMethodReallyPublic(method) && !RemotingServices.IsMethodAllowedRemotely(method)) { throw new RemotingException( Environment.GetResourceString( "Remoting_NonPublicOrStaticCantBeCalledRemotely")); } RemotingMethodCachedData cache = (RemotingMethodCachedData) InternalRemotingServices.GetReflectionCachedData(method); /* * FUTURE: * Dispatching asynchronously was cut from v1. We should reactivate * the following code in v1.x or v2. * * // look for async method version * MethodInfo begin; * MethodInfo end; * ServerChannelSinkStack serverSinkStack = sinkStack as ServerChannelSinkStack; * if ((sinkStack != null) && * cache.GetAsyncMethodVersion(out begin, out end)) * { * processing = ServerProcessing.Async; * IMessage asyncMsg = * new AsyncMethodCallMessageWrapper( * (IMethodCallMessage)msg, * begin, * new AsyncCallback(sinkStack.ServerCallback), * null); * serverSinkStack.AsyncMessage = asyncMsg; * serverSinkStack.AsyncEnd = end; * serverSinkStack.Message = (IMethodCallMessage)msg; * asyncMsg.Properties["__SinkStack"] = sinkStack; * * // We don't dispatch yet. That happens when the server transport sink * // eventually calls sinkStack.StoreAndDispatch(...). * } * else */ if (RemotingServices.IsOneWay(method)) { processing = ServerProcessing.OneWay; ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, null); } else { // regular processing processing = ServerProcessing.Complete; if (!srvId.ServerType.IsContextful) { Object[] args = new Object[] { msg, srvId.ServerContext }; replyMsg = (IMessage)CrossContextChannel.SyncProcessMessageCallback(args); } else { replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg); } } } // end of case for IMethodCallMessage } catch (Exception e) { if (processing != ServerProcessing.OneWay) { try { IMethodCallMessage mcm = (IMethodCallMessage)((msg != null)?msg:new ErrorMessage()); replyMsg = (IMessage) new ReturnMessage(e, mcm); if (msg != null) { ((ReturnMessage)replyMsg).SetLogicalCallContext( (LogicalCallContext) msg.Properties[Message.CallContextKey]); } } catch (Exception) { // Fatal exception .. ignore } } } return(processing); } // DispatchMessage
[System.Security.SecurityCritical] // auto-generated public virtual IMessage SyncProcessMessage(IMessage reqMsg) { Message.DebugOut("\n::::::::::::::::::::::::: CrossAppDomain Channel: [....] call starting"); IMessage errMsg = InternalSink.ValidateMessage(reqMsg); if (errMsg != null) { return(errMsg); } // currentPrincipal is used to save the current principal. It should be // restored on the reply message. IPrincipal currentPrincipal = null; IMessage desRetMsg = null; try { IMethodCallMessage mcmReqMsg = reqMsg as IMethodCallMessage; if (mcmReqMsg != null) { LogicalCallContext lcc = mcmReqMsg.LogicalCallContext; if (lcc != null) { // Special case Principal since if might not be serializable currentPrincipal = lcc.RemovePrincipalIfNotSerializable(); } } MemoryStream reqStm = null; SmuggledMethodCallMessage smuggledMcm = SmuggledMethodCallMessage.SmuggleIfPossible(reqMsg); if (smuggledMcm == null) { //*********************** SERIALIZE REQ-MSG **************** // Deserialization of objects requires permissions that users // of remoting are not guaranteed to possess. Since remoting // can guarantee that it's users can't abuse deserialization // (since it won't allow them to pass in raw blobs of // serialized data), it should assert the permissions // necessary before calling the deserialization code. This // will terminate the security stackwalk caused when // serialization checks for the correct permissions at the // remoting stack frame so the check won't continue on to // the user and fail. <EMAIL>[from [....]]</EMAIL> // We will hold off from doing this for x-process channels // until the big picture of distributed security is finalized. reqStm = CrossAppDomainSerializer.SerializeMessage(reqMsg); } // Retrieve calling caller context here, where it is safe from the view // of app domain checking code LogicalCallContext oldCallCtx = CallContext.SetLogicalCallContext(null); // Call helper method here, to avoid confusion with stack frames & app domains MemoryStream retStm = null; byte[] responseBytes = null; SmuggledMethodReturnMessage smuggledMrm; try { if (smuggledMcm != null) { responseBytes = DoTransitionDispatch(null, smuggledMcm, out smuggledMrm); } else { responseBytes = DoTransitionDispatch(reqStm.GetBuffer(), null, out smuggledMrm); } } finally { CallContext.SetLogicalCallContext(oldCallCtx); } if (smuggledMrm != null) { ArrayList deserializedArgs = smuggledMrm.FixupForNewAppDomain(); desRetMsg = new MethodResponse((IMethodCallMessage)reqMsg, smuggledMrm, deserializedArgs); } else { if (responseBytes != null) { retStm = new MemoryStream(responseBytes); Message.DebugOut("::::::::::::::::::::::::::: CrossAppDomain Channel: [....] call returning!!\n"); //*********************** DESERIALIZE RET-MSG ************** desRetMsg = CrossAppDomainSerializer.DeserializeMessage(retStm, reqMsg as IMethodCallMessage); } } } catch (Exception e) { Message.DebugOut("Arrgh.. XAppDomainSink::throwing exception " + e + "\n"); try { desRetMsg = new ReturnMessage(e, (reqMsg as IMethodCallMessage)); } catch (Exception) { // Fatal Error .. can't do much here } } // restore the principal if necessary. if (currentPrincipal != null) { IMethodReturnMessage mrmRetMsg = desRetMsg as IMethodReturnMessage; if (mrmRetMsg != null) { LogicalCallContext lcc = mrmRetMsg.LogicalCallContext; lcc.Principal = currentPrincipal; } } return(desRetMsg); }
public virtual IMessage SyncProcessMessage(IMessage reqMsg) { IMessage message = InternalSink.ValidateMessage(reqMsg); if (message != null) { return(message); } IPrincipal principal = null; IMessage message2 = null; try { SmuggledMethodReturnMessage message5; IMethodCallMessage message3 = reqMsg as IMethodCallMessage; if (message3 != null) { LogicalCallContext logicalCallContext = message3.LogicalCallContext; if (logicalCallContext != null) { principal = logicalCallContext.RemovePrincipalIfNotSerializable(); } } MemoryStream stream = null; SmuggledMethodCallMessage smuggledMcm = SmuggledMethodCallMessage.SmuggleIfPossible(reqMsg); if (smuggledMcm == null) { stream = CrossAppDomainSerializer.SerializeMessage(reqMsg); } LogicalCallContext callCtx = CallContext.SetLogicalCallContext(null); MemoryStream stm = null; byte[] buffer = null; try { if (smuggledMcm != null) { buffer = this.DoTransitionDispatch(null, smuggledMcm, out message5); } else { buffer = this.DoTransitionDispatch(stream.GetBuffer(), null, out message5); } } finally { CallContext.SetLogicalCallContext(callCtx); } if (message5 != null) { ArrayList deserializedArgs = message5.FixupForNewAppDomain(); message2 = new MethodResponse((IMethodCallMessage)reqMsg, message5, deserializedArgs); } else if (buffer != null) { stm = new MemoryStream(buffer); message2 = CrossAppDomainSerializer.DeserializeMessage(stm, reqMsg as IMethodCallMessage); } } catch (Exception exception) { try { message2 = new ReturnMessage(exception, reqMsg as IMethodCallMessage); } catch (Exception) { } } if (principal != null) { IMethodReturnMessage message6 = message2 as IMethodReturnMessage; if (message6 != null) { message6.LogicalCallContext.Principal = principal; } } return(message2); }
public static ServerProcessing DispatchMessage( IServerChannelSinkStack sinkStack, IMessage msg, out IMessage replyMsg) { ServerProcessing processing = ServerProcessing.Complete; replyMsg = null; try { if (null == msg) { throw new ArgumentNullException("msg"); } BCLDebug.Trace("REMOTE", "Dispatching for URI " + InternalSink.GetURI(msg)); // we must switch to the target context of the object and call the context chains etc... // Currenly XContextChannel does exactly so. So this method is just a wrapper.. // Make sure that incoming calls are counted as a remote call. This way it // makes more sense on a server. IncrementRemoteCalls(); // Check if the object has been disconnected or if it is // a well known object then we have to create it lazily. ServerIdentity srvId = CheckDisconnectedOrCreateWellKnownObject(msg); // Make sure that this isn't an AppDomain object since we don't allow // calls to the AppDomain from out of process (and x-process calls // are always dispatched through this method) if (srvId.ServerType == typeof(System.AppDomain)) { throw new RemotingException( Environment.GetResourceString( "Remoting_AppDomainsCantBeCalledRemotely")); } IMethodCallMessage mcm = msg as IMethodCallMessage; if (mcm == null) { // It's a plain IMessage, so just check to make sure that the // target object implements IMessageSink and dispatch synchronously. if (!typeof(IMessageSink).IsAssignableFrom(srvId.ServerType)) { throw new RemotingException( Environment.GetResourceString( "Remoting_AppDomainsCantBeCalledRemotely")); } processing = ServerProcessing.Complete; replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg); } else { // It's an IMethodCallMessage. // Check if the method is one way. Dispatch one way calls in // an asynchronous manner MethodInfo method = (MethodInfo)mcm.MethodBase; // X-process / X-machine calls should be to non-static // public methods only! Non-public or static methods can't // be called remotely. if ((!method.IsPublic || method.IsStatic) && !RemotingServices.IsMethodAllowedRemotely(method)) { throw new RemotingException( Environment.GetResourceString( "Remoting_NonPublicOrStaticCantBeCalledRemotely")); } RemotingMethodCachedData cache = (RemotingMethodCachedData) InternalRemotingServices.GetReflectionCachedData(method); if (RemotingServices.IsOneWay(method)) { processing = ServerProcessing.OneWay; ChannelServices.GetCrossContextChannelSink().AsyncProcessMessage(msg, null); } else { // regular processing processing = ServerProcessing.Complete; replyMsg = ChannelServices.GetCrossContextChannelSink().SyncProcessMessage(msg); } } // end of case for IMethodCallMessage } catch (Exception e) { if (processing != ServerProcessing.OneWay) { try { IMethodCallMessage mcm = (IMethodCallMessage)((msg != null)?msg:new ErrorMessage()); replyMsg = (IMessage) new ReturnMessage(e, mcm); if (msg != null) { ((ReturnMessage)replyMsg).SetLogicalCallContext( (LogicalCallContext) msg.Properties[Message.CallContextKey]); } } catch (Exception) { // Fatal exception .. ignore } } } return(processing); } // DispatchMessage
public virtual IMessage SyncProcessMessage(IMessage reqMsg) { IMessage message1 = InternalSink.ValidateMessage(reqMsg); if (message1 != null) { return(message1); } IPrincipal principal = (IPrincipal)null; IMessage message2 = (IMessage)null; try { IMethodCallMessage methodCallMessage = reqMsg as IMethodCallMessage; if (methodCallMessage != null) { LogicalCallContext logicalCallContext = methodCallMessage.LogicalCallContext; if (logicalCallContext != null) { principal = logicalCallContext.RemovePrincipalIfNotSerializable(); } } MemoryStream memoryStream = (MemoryStream)null; SmuggledMethodCallMessage smuggledMcm = SmuggledMethodCallMessage.SmuggleIfPossible(reqMsg); if (smuggledMcm == null) { memoryStream = CrossAppDomainSerializer.SerializeMessage(reqMsg); } LogicalCallContext callCtx = CallContext.SetLogicalCallContext((LogicalCallContext)null); byte[] buffer = (byte[])null; SmuggledMethodReturnMessage smuggledMrm; try { buffer = smuggledMcm == null?this.DoTransitionDispatch(memoryStream.GetBuffer(), (SmuggledMethodCallMessage)null, out smuggledMrm) : this.DoTransitionDispatch((byte[])null, smuggledMcm, out smuggledMrm); } finally { CallContext.SetLogicalCallContext(callCtx); } if (smuggledMrm != null) { ArrayList deserializedArgs = smuggledMrm.FixupForNewAppDomain(); message2 = (IMessage) new MethodResponse((IMethodCallMessage)reqMsg, smuggledMrm, deserializedArgs); } else if (buffer != null) { message2 = CrossAppDomainSerializer.DeserializeMessage(new MemoryStream(buffer), reqMsg as IMethodCallMessage); } } catch (Exception ex1) { try { message2 = (IMessage) new ReturnMessage(ex1, reqMsg as IMethodCallMessage); } catch (Exception ex2) { } } if (principal != null) { IMethodReturnMessage methodReturnMessage = message2 as IMethodReturnMessage; if (methodReturnMessage != null) { methodReturnMessage.LogicalCallContext.Principal = principal; } } return(message2); }