/// <summary>
        /// Forward aCommand to remote service.
        /// </summary>
        /// <param name="command">The Command to be forwarded</param>
        /// <param name="destination">String that represent the address of the target service.</param>
        private void ForwardCommand(Command command, string destination, string rootSender)
        {
            if (debug)
                Console.WriteLine("{0} Forwarding a {1} to {2}",LogTimestamp, command.GetType().Name, destination.Split('/').Last().ToUpper());

            /** Invoke the remote node service via the dedicated forward endpoint address. */
            BasicHttpBinding fwdBinding = new BasicHttpBinding();
            EndpointAddress fwdEndpoint = new EndpointAddress(destination);
            ChannelFactory<IDarPoolingForwarding> fwdChannelFactory = new ChannelFactory<IDarPoolingForwarding>(fwdBinding, fwdEndpoint);
            IDarPoolingForwarding destinationService = fwdChannelFactory.CreateChannel();

            //string senderAddress = receiver.BaseForwardAddress + receiver.NodeName;

            destinationService.HandleForwardedDarPoolingRequest(command, rootSender);

            /** Close the channel: the communication is fire-and-forget (one-way) */
            ((IClientChannel)destinationService).Close();
            fwdChannelFactory.Close();
        }
        /// <summary>
        /// IDarPoolingForwarding method. The service node obtain the result of the forwarded command.
        /// </summary>
        /// <param name="forwardedCommand"></param>
        /// <param name="finalResult"></param>
        public void ReturnFinalResult(Result result, Command originalCommand)
        {
            if (IsFwdCommand(originalCommand.CommandID))
            {
                string senderAddress = ExtractService(originalCommand.CommandID);
                // Get ready to contact the sender Service node.
                BasicHttpBinding myBinding = new BasicHttpBinding();
                EndpointAddress myEndpoint = new EndpointAddress(senderAddress);
                ChannelFactory<IDarPoolingForwarding> myChannelFactory = new ChannelFactory<IDarPoolingForwarding>(myBinding, myEndpoint);
                IDarPoolingForwarding service = myChannelFactory.CreateChannel();

                // Give the result back to the the sender Service node.
                service.ReturnFinalResult(result, originalCommand);
                // Close channel.
                ((IClientChannel)service).Close();
                myChannelFactory.Close();
            }
            else
            {
                if (debug)
                {
                    TimeSpan totalTime = DateTime.Now.Subtract(originalCommand.Timestamp);
                    Console.WriteLine("{0} Total time for {1}: {2}", LogTimestamp, originalCommand.GetType().Name, totalTime.TotalMilliseconds);
                }
                if (IsMobileCommand(originalCommand.CommandID))
                {
                   Console.WriteLine("\n{0} Ready to send the result back to Mobile", LogTimestamp);
                   mobile.AddMobileResult(originalCommand.CommandID, result);
                   //mobile.

                }
                else
                {
                    IDarPoolingCallback client = ExtractClient(originalCommand.CommandID);
                    ReturnResultToClient(result, client);
                }
            }
        }
        /// <summary>
        /// IDarPoolingForwarding method. The user-related command uses only one hop,
        /// i.e. they always reach the correct and final destination node with only
        /// one connession. For these reasons, we only have to execute the command,
        /// and the return the result to the rootSender service node.
        /// </summary>
        /// <param name="forwardedCommand"></param>
        public void HandleForwardedDarPoolingRequest(Command fwdCommand, string rootSenderAddress)
        {
            if (debug)
                Console.WriteLine("{0} {1} node received FWD_{2}",LogTimestamp, receiver.NodeName.ToUpper(), fwdCommand.GetType().Name);

            AddFwdCommandService(fwdCommand.CommandID, rootSenderAddress);
            fwdCommand.Receiver = receiver;
            fwdCommand.Callback = new AsyncCallback(ProcessResultOfForwardedCommand);
            fwdCommand.Execute();
        }
        public void HandleMobileDarPoolingRequest(Command command)
        {
            if (debug)
                Console.WriteLine("\n{0} {1} node received {2}", LogTimestamp, receiver.NodeName.ToUpper(), command.GetType());

            /** Assign a GUID to the command. */
            pendingMobileCommands.Add(command.CommandID, command);

            /** Set a ServiceNodeCore as the receiver of the command and execute the command. */
            command.Timestamp = DateTime.Now;
            command.Receiver = receiver;
            command.Callback = new AsyncCallback(ProcessResult);
            command.Execute();
        }
        /// <summary>
        /// Execute request of clients.
        /// </summary>
        /// <param name="command">The Command object, sent by a client</param>
        public void HandleDarPoolingRequest(Command command)
        {
            if (debug)
                Console.WriteLine("\n{0} {1} node received {2}",LogTimestamp, receiver.NodeName.ToUpper(),command.GetType());

            /** Assign a GUID to the command. */
            command.CommandID = generateGUID();
            /** Save information about the client that has sent the command. */
            IDarPoolingCallback client = OperationContext.Current.GetCallbackChannel<IDarPoolingCallback>();
            commandClient.Add(command.CommandID, client);

            /** Set a ServiceNodeCore as the receiver of the command and execute the command. */
            command.Timestamp = DateTime.Now;
            command.Receiver = receiver;
            command.Callback = new AsyncCallback(ProcessResult);
            command.Execute();
        }