Skip to content

Instantly share code, notes, and snippets.

@kumpera
Created February 26, 2013 19:14
Show Gist options
  • Select an option

  • Save kumpera/5041190 to your computer and use it in GitHub Desktop.

Select an option

Save kumpera/5041190 to your computer and use it in GitHub Desktop.
using System;
using NUnit.Framework;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Proxies;
using System.Runtime.Remoting.Messaging;
namespace remoting
{
public class MyProxy : RealProxy {
MarshalByRefObject obj;
string uri;
public MyProxy(Type myType) : base(myType)
{
obj = (MarshalByRefObject)Activator.CreateInstance((myType));
var oref = RemotingServices.Marshal(obj);
uri = oref.URI;
Console.WriteLine ("URI is {0}", uri);
}
public override IMessage Invoke (IMessage msg)
{
Console.WriteLine ("Invoke {0}", msg);
msg.Properties ["__Uri"] = uri;
return ChannelServices.SyncDispatchMessage (msg);
}
}
class Foo : MarshalByRefObject
{
public string Bar () { return "real"; }
}
[TestFixture]
public class TransparentProxyTest
{
[Test]
public void Pass ()
{
var rp = new MyProxy (typeof (Foo));
var foo = (Foo)rp.GetTransparentProxy ();
Assert.AreEqual ("real", foo.Bar ());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment