public override IMessage Invoke(IMessage msg) { IMethodCallMessage call = (IMethodCallMessage)msg; if (call.MethodName.StartsWith("Initialize")) { return(new ReturnMessage(null, null, 0, null, (IMethodCallMessage)msg)); } call.Properties["__Uri"] = _uri; if (_stream != null) { SerializeCall(call); IMessage response = ChannelServices.SyncDispatchMessage(call); SerializeResponse(response); return(response); } else if (_testMsg != null) { if (_testMsg is IMethodCallMessage) { return(ChannelServices.SyncDispatchMessage(_testMsg)); } else { return(_testMsg); } } else { return(ChannelServices.SyncDispatchMessage(call)); } }
internal void ProcessMessageInDomain(byte[] arrRequest, CADMethodCallMessage cadMsg, out byte[] arrResponse, out CADMethodReturnMessage cadMrm) { IMessage reqDomMsg; if (null != arrRequest) { reqDomMsg = CADSerializer.DeserializeMessage(new MemoryStream(arrRequest), null); } else { reqDomMsg = new MethodCall(cadMsg); } IMessage retDomMsg = ChannelServices.SyncDispatchMessage(reqDomMsg); cadMrm = CADMethodReturnMessage.Create(retDomMsg); if (null == cadMrm) { arrResponse = CADSerializer.SerializeMessage(retDomMsg).GetBuffer(); } else { arrResponse = null; } }
public override IMessage Invoke(IMessage myMessage) { Console.WriteLine("MyProxy 'Invoke method' Called..."); if (myMessage is IMethodCallMessage) { Console.WriteLine("IMethodCallMessage"); } if (myMessage is IMethodReturnMessage) { Console.WriteLine("IMethodReturnMessage"); } if (myMessage is IConstructionCallMessage) { // Initialize a new instance of remote object IConstructionReturnMessage myIConstructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)myMessage); ConstructionResponse constructionResponse = new ConstructionResponse(null, (IMethodCallMessage)myMessage); return(constructionResponse); } IDictionary myIDictionary = myMessage.Properties; IMessage returnMessage; myIDictionary["__Uri"] = myUri; // Synchronously dispatch messages to server. returnMessage = ChannelServices.SyncDispatchMessage(myMessage); // Pushing return value and OUT parameters back onto stack. IMethodReturnMessage myMethodReturnMessage = (IMethodReturnMessage)returnMessage; return(returnMessage); }
void ProcessRequest(ISmtpMessage smtpMessage, Smtp.Fields headers, Header[] msgHeaders, String contentType, String seqNum, MemoryStream stm, ref bool fIsOneWay) { IMessage outMsg = null; fIsOneWay = false; // Deserialize - Stream to IMessage IMessage inMsg = CoreChannel.DeserializeMessage(contentType, stm, true, null, msgHeaders); InternalRemotingServices.RemotingTrace("Deserialized message"); if (inMsg == null) { throw new Exception(CoreChannel.GetResourceString("Remoting_DeserializeMessage")); } // Set URI - BUGBUG: temp hack String url = ((IMethodMessage)inMsg).Uri; String objectURL = null; try { Parse(url, out objectURL); } catch (Exception) { objectURL = url; } inMsg.Properties["__Uri"] = objectURL; // Dispatch Call InternalRemotingServices.RemotingTrace("ChannelServices.SyncDispatchMessage - before"); outMsg = ChannelServices.SyncDispatchMessage(inMsg); InternalRemotingServices.RemotingTrace("ChannelServices.SyncDispatchMessage - after"); // We do not send a reply for one way messages. If the message // is not one way and we have a null return message then we // throw an exception if (null == outMsg) { MethodBase method = ((IMethodMessage)inMsg).MethodBase; fIsOneWay = RemotingServices.IsOneWay(method); if (!fIsOneWay) { throw new Exception(CoreChannel.GetResourceString("Remoting_DispatchMessage")); } } else { ReplyMessage(outMsg, smtpMessage, seqNum, headers); InternalRemotingServices.RemotingTrace("Reply sent"); } }
public override IMessage Invoke(IMessage myIMessage) { MarshalByRefObject obj2 = (MarshalByRefObject)Activator.CreateInstance(this._type); string uRI = RemotingServices.Marshal(obj2).URI; myIMessage.Properties["__Uri"] = uRI; Type type = obj2.GetType(); IMethodCallMessage callMessage = (IMethodCallMessage)myIMessage; MethodInfo pMehotdInfo = type.GetMethods().Where <MethodInfo>(delegate(MethodInfo x) { return(x.ToString().Equals(callMessage.MethodBase.ToString())); }).FirstOrDefault <MethodInfo>(); if (pMehotdInfo == null) { this.MethodNotFound(callMessage.MethodName, type.ToString()); } IMessage message = null; TransactionScope scope = null; bool flag = false; try { if (this.UsingTransaction) { scope = new TransactionScope(); } this.BeforeInvoke(); if (this.ValidateCanInvoke(pMehotdInfo)) { message = ChannelServices.SyncDispatchMessage(myIMessage); } this.AfterInvoke(); } catch { flag = true; throw; } finally { if (scope != null) { if (!flag) { scope.Complete(); } scope.Dispose(); } } return(message); }
public override IMessage Invoke(IMessage message) { message.Properties["__Uri"] = stringUri; IMethodMessage myMethodMessage = (IMethodMessage)ChannelServices.SyncDispatchMessage(message); Console.WriteLine("---------IMethodMessage example-------"); Console.WriteLine("Method name : " + myMethodMessage.MethodName); Console.WriteLine("LogicalCallContext has information : " + myMethodMessage.LogicalCallContext.HasInfo); Console.WriteLine("Uri : " + myMethodMessage.Uri); return(myMethodMessage); }
public override IMessage Invoke(IMessage msg) { if (msg is IConstructionCallMessage) { // Initialize a new instance of remote object IConstructionReturnMessage myIConstructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg); ConstructionResponse constructionResponse = new ConstructionResponse(null, (IMethodCallMessage)msg); return(constructionResponse); } IDictionary myIDictionary = msg.Properties; IMessage retMsg; myIDictionary["__Uri"] = m_URI; // Synchronously dispatch messages to server. retMsg = ChannelServices.SyncDispatchMessage(msg); // Pushing return value and OUT parameters back onto stack IMethodReturnMessage mrm = (IMethodReturnMessage)retMsg; return(retMsg); }
// You can find more info on what can be done in here off MSDN. public override IMessage Invoke(IMessage message) { Console.WriteLine("Invoke!"); message.Properties["__Uri"] = uri; return(ChannelServices.SyncDispatchMessage(message)); }
public override IMessage Invoke(IMessage myIMessage) { Console.WriteLine("**********************************************************************************"); IDictionary myIDictionary = myIMessage.Properties; // Set the '__Uri' property of 'IMessage' to 'URI' property of 'ObjRef'. myIDictionary["__Uri"] = stringUri; IDictionaryEnumerator myIDictionaryEnumerator = (IDictionaryEnumerator)myIDictionary.GetEnumerator(); while (myIDictionaryEnumerator.MoveNext()) { Object myKey = myIDictionaryEnumerator.Key; String myKeyName = myKey.ToString(); Object myValue = myIDictionaryEnumerator.Value; Console.WriteLine("\t{0} : {1}", myKeyName, myIDictionaryEnumerator.Value); if (myKeyName == "__Args") { Object[] objs = (Object[])myValue; for (int aIndex = 0; aIndex < objs.Length; aIndex++) { Console.WriteLine("\t\targ: {0} myValue: {1}", aIndex, objs[aIndex]); } } if ((myKeyName == "__MethodSignature") && (null != myValue)) { Object[] objs = (Object[])myValue; for (int aIndex = 0; aIndex < objs.Length; aIndex++) { Console.WriteLine("\t\targ: {0} myValue: {1}", aIndex, objs[aIndex]); } } } Console.WriteLine("**********************************************************************************"); Console.WriteLine("ChannelServices.SyncDispatchMessage"); IMessage myReturnMessage = ChannelServices.SyncDispatchMessage(myIMessage); // Push return value and OUT parameters back onto stack. IMethodReturnMessage myMethodReturnMessage = (IMethodReturnMessage)myReturnMessage; Console.WriteLine("IMethodReturnMessage.ReturnValue: {0}", myMethodReturnMessage.ReturnValue); Console.WriteLine("**********************************************************************************"); IMethodCallMessage myIMethodCallMessage = (IMethodCallMessage)myIMessage; IMethodReturnMessage myIMethodReturnMessage = RemotingServices.ExecuteMessage(myMarshalByRefObject, myIMethodCallMessage); Console.WriteLine("Method name : " + myIMethodReturnMessage.MethodName); Console.WriteLine("The return value is : " + myIMethodReturnMessage.ReturnValue); Console.WriteLine("**********************************************************************************"); int myArgOutCount = myIMethodReturnMessage.OutArgCount; Console.WriteLine("The number of 'ref', 'out' parameters are : " + myIMethodReturnMessage.OutArgCount); // Gets name and values of 'ref' and 'out' parameters. for (int i = 0; i < myArgOutCount; i++) { Console.WriteLine("Name of argument {0} is '{1}'.", i, myIMethodReturnMessage.GetOutArgName(i)); Console.WriteLine("Value of argument {0} is '{1}'.", i, myIMethodReturnMessage.GetOutArg(i)); } Console.WriteLine(); object[] myObjectArray = myIMethodReturnMessage.OutArgs; for (int i = 0; i < myObjectArray.Length; i++) { Console.WriteLine("Value of argument {0} is '{1}' in OutArgs", i, myObjectArray[i]); } Console.WriteLine("**********************************************************************************"); Console.WriteLine("Message is of type 'IMethodCallMessage'."); Console.WriteLine("InArgCount is : " + myIMethodCallMessage.InArgCount); foreach (object arg in myIMethodCallMessage.InArgs) { Console.WriteLine("InArgs is : " + arg); } for (int i = 0; i < myIMethodCallMessage.InArgCount; i++) { Console.WriteLine("GetArgName(" + i + ") is : " + myIMethodCallMessage.GetArgName(i)); Console.WriteLine("GetInArg(" + i + ") is : " + myIMethodCallMessage.GetInArg(i)); } Console.WriteLine("**********************************************************************************"); var message = new ReturnMessage(5, null, 0, null, (IMethodCallMessage)myIMessage); return(message); }
public override IMessage Invoke(IMessage myIMessage) { Console.WriteLine("MyProxy.Invoke Start"); Console.WriteLine(""); if (myIMessage is IMethodCallMessage) { Console.WriteLine("IMethodCallMessage"); } if (myIMessage is IMethodReturnMessage) { Console.WriteLine("IMethodReturnMessage"); } Type msgType = myIMessage.GetType(); Console.WriteLine("Message Type: {0}", msgType.ToString()); Console.WriteLine("Message Properties"); IDictionary myIDictionary = myIMessage.Properties; // Set the '__Uri' property of 'IMessage' to 'URI' property of 'ObjRef'. myIDictionary["__Uri"] = myURIString; IDictionaryEnumerator myIDictionaryEnumerator = (IDictionaryEnumerator)myIDictionary.GetEnumerator(); while (myIDictionaryEnumerator.MoveNext()) { Object myKey = myIDictionaryEnumerator.Key; String myKeyName = myKey.ToString(); Object myValue = myIDictionaryEnumerator.Value; Console.WriteLine("\t{0} : {1}", myKeyName, myIDictionaryEnumerator.Value); if (myKeyName == "__Args") { Object[] myObjectArray = (Object[])myValue; for (int aIndex = 0; aIndex < myObjectArray.Length; aIndex++) { Console.WriteLine("\t\targ: {0} myValue: {1}", aIndex, myObjectArray[aIndex]); } } if ((myKeyName == "__MethodSignature") && (null != myValue)) { Object[] myObjectArray = (Object[])myValue; for (int aIndex = 0; aIndex < myObjectArray.Length; aIndex++) { Console.WriteLine("\t\targ: {0} myValue: {1}", aIndex, myObjectArray[aIndex]); } } } IMessage myReturnMessage; myIDictionary["__Uri"] = myURIString; Console.WriteLine("__Uri {0}", myIDictionary["__Uri"]); Console.WriteLine("ChannelServices.SyncDispatchMessage"); myReturnMessage = ChannelServices.SyncDispatchMessage(myIMessage); // Push return value and OUT parameters back onto stack. IMethodReturnMessage myMethodReturnMessage = (IMethodReturnMessage) myReturnMessage; Console.WriteLine("IMethodReturnMessage.ReturnValue: {0}", myMethodReturnMessage.ReturnValue); Console.WriteLine("MyProxy.Invoke - Finish"); return(myReturnMessage); }
public override IMessage Invoke(IMessage msg) { msg.Properties["__Uri"] = this.uri; return(ChannelServices.SyncDispatchMessage(msg)); }