Ejemplo n.º 1
0
        /// <summary>
        /// Sends remote method invocation message to the remote application and gets result.
        /// This simplifies remove method invocation like calling a method locally.
        /// It throws Exception if any Exception occured on remote application's method.
        /// </summary>
        /// <param name="methodName">Method name to invoke</param>
        /// <param name="args">Method parameters</param>
        /// <returns>Return value of remote method</returns>
        protected object InvokeRemoteMethodAndGetResult(string methodName, params object[] args)
        {
            //Create NGRIDRemoteInvokeMessage object that contains invocation informations
            var invokeMessage = new NGRIDRemoteInvokeMessage { ServiceClassName = _serviceClassName, MethodName = methodName, Parameters = args };

            //Create NGRID message to transmit NGRIDRemoteInvokeMessage.
            var outgoingMessage = _serviceConsumer.NgridClient.CreateMessage();
            outgoingMessage.DestinationServerName = RemoteApplication.ServerName;
            outgoingMessage.DestinationApplicationName = RemoteApplication.ApplicationName;
            outgoingMessage.DestinationCommunicatorId = RemoteApplication.CommunicatorId;
            outgoingMessage.TransmitRule = MessageTransmitRules.DirectlySend;
            outgoingMessage.MessageData = GeneralHelper.SerializeObject(invokeMessage);

            //Send message and get response
            var incomingMessage = outgoingMessage.SendAndGetResponse(Timeout);
            incomingMessage.Acknowledge();

            //Deserialize and check return value
            var invokeReturnMessage = (NGRIDRemoteInvokeReturnMessage) GeneralHelper.DeserializeObject(incomingMessage.MessageData);
            if (invokeReturnMessage.RemoteException != null)
            {
                throw invokeReturnMessage.RemoteException;
            }

            //Success
            return invokeReturnMessage.ReturnValue;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends remote method invocation message to the remote application and gets result.
        /// This simplifies remove method invocation like calling a method locally.
        /// It throws Exception if any Exception occured on remote application's method.
        /// </summary>
        /// <param name="methodName">Method name to invoke</param>
        /// <param name="args">Method parameters</param>
        /// <returns>Return value of remote method</returns>
        protected object InvokeRemoteMethodAndGetResult(string methodName, params object[] args)
        {
            //Create NGRIDRemoteInvokeMessage object that contains invocation informations
            var invokeMessage = new NGRIDRemoteInvokeMessage {
                ServiceClassName = _serviceClassName, MethodName = methodName, Parameters = args
            };

            //Create NGRID message to transmit NGRIDRemoteInvokeMessage.
            var outgoingMessage = _serviceConsumer.NgridClient.CreateMessage();

            outgoingMessage.DestinationServerName      = RemoteApplication.ServerName;
            outgoingMessage.DestinationApplicationName = RemoteApplication.ApplicationName;
            outgoingMessage.DestinationCommunicatorId  = RemoteApplication.CommunicatorId;
            outgoingMessage.TransmitRule = MessageTransmitRules.DirectlySend;
            outgoingMessage.MessageData  = GeneralHelper.SerializeObject(invokeMessage);

            //Send message and get response
            var incomingMessage = outgoingMessage.SendAndGetResponse(Timeout);

            incomingMessage.Acknowledge();

            //Deserialize and check return value
            var invokeReturnMessage = (NGRIDRemoteInvokeReturnMessage)GeneralHelper.DeserializeObject(incomingMessage.MessageData);

            if (invokeReturnMessage.RemoteException != null)
            {
                throw invokeReturnMessage.RemoteException;
            }

            //Success
            return(invokeReturnMessage.ReturnValue);
        }