internal class CrossAppDomainSink : IMessageSink \r
{\r
private static Hashtable s_sinks = new Hashtable();\r
+
+ private static MethodInfo processMessageMethod =
+ typeof (CrossAppDomainSink).GetMethod ("ProcessMessageInDomain", BindingFlags.NonPublic|BindingFlags.Static);
+
\r
private int _domainID;\r
\r
}\r
}\r
}
+
+ private struct ProcessMessageRes {
+ public byte[] arrResponse;
+ public CADMethodReturnMessage cadMrm;
+ }
+
+ private static ProcessMessageRes ProcessMessageInDomain (
+ byte[] arrRequest,
+ CADMethodCallMessage cadMsg)
+ {
+ ProcessMessageRes res = new ProcessMessageRes ();
+
+ try
+ {
+ AppDomain.CurrentDomain.ProcessMessageInDomain (arrRequest, cadMsg, out res.arrResponse, out res.cadMrm);
+ }
+ catch (Exception e)
+ {
+ IMessage errorMsg = new MethodResponse (e, new ErrorMessage());
+ res.arrResponse = CADSerializer.SerializeMessage (errorMsg).GetBuffer(); \r
+ }
+ return res;
+ }
\r
public virtual IMessage SyncProcessMessage(IMessage msgRequest) \r
{\r
\r
object threadStatus = Thread.ResetDataStoreStatus ();\r
Context currentContext = Thread.CurrentContext;
- AppDomain currentDomain = AppDomain.InternalSetDomainByID ( _domainID );\r
- try
- {
- AppDomain.CurrentDomain.ProcessMessageInDomain (arrRequest, cadMsg, out arrResponse, out cadMrm);
+ try {
+ // InternalInvoke can't handle out arguments, this is why
+ // we return the results in a structure
+ ProcessMessageRes res = (ProcessMessageRes)AppDomain.InvokeInDomainByID (_domainID, processMessageMethod, null, new object [] { arrRequest, cadMsg });
+ arrResponse = res.arrResponse;
+ cadMrm = res.cadMrm;
}
- catch (Exception e)
- {
- IMessage errorMsg = new MethodResponse (e, new ErrorMessage());
- arrResponse = CADSerializer.SerializeMessage (errorMsg).GetBuffer(); \r
- }
- finally
- {
- AppDomain.InternalSetDomain (currentDomain);
+ finally {
AppDomain.InternalSetContext (currentContext);
- Thread.RestoreDataStoreStatus (threadStatus);\r
- }\r
+ Thread.RestoreDataStoreStatus (threadStatus);
+ }
+
\r
if (null != arrResponse) {\r
// Time to deserialize the message\r
{\r
try\r
{\r
- Console.WriteLine("Exception in base domain");
retMessage = new ReturnMessage (e, msgRequest as IMethodCallMessage);
}\r
catch (Exception)\r