Code Puzzle – Get Behind Firewall – Solution

I feel really disappointed because I have not received any solution from anyone for this puzzle. The solution to this is very trivial with the correct tools. Tool I am using to solve this is Simple Service Bus. I want to remind you what was the architectural design pattern.

image

And below you can find very trivial and working solution. Can you explain why nobody solves this? Just wonder. The only thing I do not tell you is how to encrypt the transport layer in this communication. This will be my secret.

Contract

namespace GetBehindFirewallMessages
{
	using System;
	using CodingByToDesign.SimpleServiceBus.Communication.Contracts;
	[Serializable]
	public class GetBehindFirewallMessageReq : IMessage
	{
		public string ApiKey { get; set; }
		public string Request { get; set; }
	}
	[Serializable]
	public class GetBehindFirewallMessageRes : IMessage
	{
		public string ApiKey { get; set; }
		public string Response { get; set; }
	}
}

Receiver (for example in public Cloud)

namespace GetBehindFirewallReceiver
{
	using CodingByToDesign.SimpleServiceBus.Communication;
	using GetBehindFirewallMessages;
	class Receiver
	{
		readonly static Requester
		<GetBehindFirewallMessageReq, GetBehindFirewallMessageRes>
		requester = new Requester
		<GetBehindFirewallMessageReq, GetBehindFirewallMessageRes>
		("net.tcp://some.site:2727/Receiver", 5000, 30000, 1000, "SessionKey");
		public static void Main(string[] args)
		{
			string response = null;
			requester.RequestSync(
				new GetBehindFirewallMessageReq
				{
					ApiKey = "SecretKey",
					Request = "SELECT 'SECRET' RESPONSE FROM DUAL"
				},
				(res) => {
					if (res.ApiKey == "SecretKey") response = res.Response;
				}
			);
			requester.Dispose();
			Console.WriteLine("Response: {0}", response);
		}
	}
}

Responder (internal corporate network)

namespace GetBehindFirewallReceiver
{
	using CodingByToDesign.SimpleServiceBus.Communication;
	using GetBehindFirewallMessages;
	class Responder
	{
		readonly static Receiver
		<GetBehindFirewallMessageReq, GetBehindFirewallMessageRes>
		receiver = new Receiver
		<GetBehindFirewallMessageReq, GetBehindFirewallMessageRes>
		("net.tcp://some.site:2727/Receiver", 5000, 30000, 1000, "SessionKey");
		public static void Main(string[] args)
		{
			receiver.RecieveAction = (transactId, req) =>
			{
				if (req.ApiKey == "SecretKey")
				{
					receiver.ResponseAsync(
						transactId,
						new GetBehindFirewallMessageRes
						{
							ApiKey = req.ApiKey,
							Response = CreateResponse(req.Request)
						}
					)
				}
			};
			Console.ReadKey(true);
			receiver.Dispose();
		}
		static string CreateResponse(string request)
		{
			if (request == "SELECT 'SECRET' RESPONSE FROM DUAL")
			{
				return @"""0"":{""RESPONSE"":""CHAR""},""1"":{""RESPONSE"":""SECRET""}";
			}
			return string.Empty;
		}
	}
}

Nobody send me solution. Nobody wins the award.

p ;).

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.