/// <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); } } }