Last active
December 11, 2015 02:39
-
-
Save rpgmaker/4532220 to your computer and use it in GitHub Desktop.
Sample Proxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ChatServiceServer : IESBMessage<ChatRequest, ChatResponse> { | |
[ESBTransport(typeof(TcpTransport))] | |
[ESBTransportParam("Port", "2222")] | |
[ESBTransportParam("IPAddress", "127.0.0.1")] | |
public ChatResponse Handle(ChatRequest msg) { | |
Console.WriteLine("Received Chat Request with ID = {0}", msg.ESBCorrelationID); | |
var response = new ChatResponse() { | |
UserName = String.Format("{0}Server", msg.UserName), | |
Message = "Server: Hello Client" | |
}; | |
return response; | |
} | |
} | |
class Program { | |
static void Main(string[] args) { | |
ProxyService.Start(); | |
Console.WriteLine("Waiting for request..... Press enter to close"); | |
Console.ReadLine(); | |
ProxyService.Shutdown(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ESBProxyService] | |
public interface IChatService { | |
[ESBTransport(typeof(TcpTransport))] | |
[ESBTransportParam("Port", "1111")] | |
[ESBTransportParam("IPAddress", "127.0.0.1")] | |
[ESBRequest(typeof(ChatRequest), isRequestClass: true)] | |
ChatResponse Execute(ChatRequest request); | |
} | |
class Program { | |
static void Main(string[] args) { | |
ProxyService.Start(); | |
var service = ProxyService.Create<IChatService>(); | |
Console.WriteLine("Press enter to send request. Type exit to close"); | |
while (true) { | |
var text = Console.ReadLine(); | |
if (text.ToLower() == "exit") break; | |
var response = service.Execute(new ChatRequest() { Message = "Hello Server", UserName = "Client" }); | |
if (response != null) | |
Console.WriteLine("{0}: {1}", response.UserName, response.Message); | |
else | |
Console.WriteLine("Could not process request"); | |
} | |
ProxyService.Shutdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment