Skip to content

Instantly share code, notes, and snippets.

@jbw
Created April 22, 2016 21:39
Show Gist options
  • Save jbw/bf8b4e3afbbefe8db16a4cd9ce38fcb1 to your computer and use it in GitHub Desktop.
Save jbw/bf8b4e3afbbefe8db16a4cd9ce38fcb1 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
namespace DotNetRemotingExample
{
/// <summary>
/// Server
/// </summary>
class Program
{
[SecurityPermission(SecurityAction.LinkDemand)]
static void Main(string[] args)
{
TcpServerChannel channel = new TcpServerChannel(9932);
ChannelServices.RegisterChannel(channel, false);
// Single call, instance created every call.
//RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotableType), "RemotableType", WellKnownObjectMode.SingleCall);
// Singleton.
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotableType), "RemotableType", WellKnownObjectMode.Singleton);
Console.WriteLine("Press Any Key");
Console.ReadLine();
}
}
/// <summary>
/// Remoteable Type
/// </summary>
public class RemotableType : MarshalByRefObject
{
public RemotableType()
{
Console.WriteLine("New reference added!");
}
public string Connect()
{
Console.WriteLine("Talking to RemoteableType.Connected");
return "Hi!";
}
public TestObject GetNewTestObject()
{
return new TestObject();
}
}
[Serializable]
public class TestObject
{
public Guid Id { get; set; }
public TestObject()
{
Id = Guid.NewGuid();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment