Skip to content

Instantly share code, notes, and snippets.

@yallie
Created April 25, 2017 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yallie/090b69bb3ed15580a0547c81fc6a36c5 to your computer and use it in GitHub Desktop.
Save yallie/090b69bb3ed15580a0547c81fc6a36c5 to your computer and use it in GitHub Desktop.
GenuineXHttpChannel sample
// Compile using: csc gxhttptest.cs /r:GenuineChannels.dll
// gxhttptest.exe /s — start server
// gxhttptest.exe — start client
using System;
using System.Collections.Generic;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using Belikov.GenuineChannels.GenuineXHttp;
namespace TestApp
{
class Program
{
static void Main(string[] args)
{
if (args.Length > 0)
{
RunServer();
return;
}
RunClient();
}
private static void RegisterChannel(bool server = false)
{
var props = new Dictionary<string, string>
{
{ "name", "ghttp" },
{ "priority", "100" }
};
if (server)
{
props["port"] = "18888";
}
ChannelServices.RegisterChannel(new GenuineXHttpChannel(props, null, null), false);
}
private static void RunServer()
{
RegisterChannel(server: true);
var service = new Service();
var objref = RemotingServices.Marshal(service, "Service.rem");
Console.WriteLine("Server started. Press ENTER to quit");
Console.ReadLine();
}
internal class Service : MarshalByRefObject, IService
{
public string Greeting(string s)
{
var result = $"Hello, {s}!";
Console.WriteLine("Replying to client: {0}", result);
return result;
}
}
public interface IService
{
string Greeting(string s);
}
private static void RunClient()
{
Console.WriteLine("Connecting to server...");
RegisterChannel();
var proxy = (IService)Activator.GetObject(typeof(IService), "ghttp://localhost:18888/Service.rem");
var greeting = proxy.Greeting("World");
Console.WriteLine("Server replies: {0}", greeting);
Console.WriteLine("Press ENTER to quit.");
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment