Hi Everybody,
I want to use functions having callback in remoting mode.Summary of scenario is
1) I am having a shared class library which has a functions which contains callback
2)Server as standalone application which used to take session from shared class library
3)Client as standalone application which takes session from serer and then call the functions on it
Summary of my code is:
SharedLibrary:
namespace TestClassLibrary
{
public class Class1 : MarshalByRefObject
{
public delegate void NotifyCallback(string s);
public void SelectWithClassDialog(string msg, NotifyCallback callback, string title)
{
Console.WriteLine("SelectWithClassDialog");
Console.WriteLine(msg);
Console.WriteLine(title);
if (callback != null)
s_notify(callback);
}
}
public class TestSession : MarshalByRefObject
{
internal TestSession()
{
}
new internal void initialize()
{
_cls1 = new Class1();
}
private Class1 _cls1;
public Class1 Class1
{
get
{
return _cls1;
}
}
static private TestSession theSession;
public static TestSession GetSession()
{
lock (typeof(TestSession))
{
if (theSession == null)
{
theSession = new TestSession();
theSession.initialize();
}
}
return theSession;
}
} ServerCode:
namespace TestServer
{
class TestServer
{
static void Main()
{
Thread serverThread = new Thread(new ThreadStart(Run));
serverThread.Start();
}
public static void Run()
{
int port = 1234;
TestSession theSession = TestSession.GetSession();
LifetimeServices.LeaseTime = System.TimeSpan.FromDays(10000);

// Create a custom FormatterSinkProvider so that we can set its security type
// filter to Full. This is necessary for ObjectRefs to be deserialised
SoapServerFormatterSinkProvider provider = new SoapServerFormatterSinkProvider();
provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilter Level.Full;

// Create the IDictionary to set the port on the channel instance.
IDictionary props = new Hashtable();
props["port"] = port;

// Create a new HTTP channel with the given provider and properties
HttpChannel channel = new HttpChannel(props, null, provider);
ChannelServices.RegisterChannel(channel, false);

// Export the Session object
RemotingServices.Marshal(theSession, "TestSession");
// Create the server object for clients to connect to
RemotingConfiguration.RegisterWellKnownServiceType (
typeof(ClientComms),
"RemoteServer",
WellKnownObjectMode.Singleton);

Thread.Sleep(Timeout.Infinite);
}
}
}

Client code:
namespace Client
{
class Program
{
private static TestSession theSession = null;
static TestClassLibrary.NotifyCallback ip = init_proc_body;
static void Main()
{
Console.WriteLine("Getting TestSession object...");
theSession = (TestSession)Activator.GetObject(typeof(TestSessio n), "http://localhost:1234/TestSession");
if (theSession == null)
{
Console.WriteLine("No Session object found. Exit.");
return;
}
Console.WriteLine("Got Session object");
theSession.Class1.SelectWithClassDialog("test", ip, "test_str"); // got exception here
}
public static void init_proc_body(String s)
{
Console.WriteLine("Inside callback");
Console.WriteLine(s);
}
}
}
In client I am trying to call function SelectWithClassDialog("test", ip, "test_str"); at this statement I will get an exception

System.Reflection.TargetInvocationException was unhandled
HResult=-2146232828
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
InnerException: System.IO.FileNotFoundException
HResult=-2147024894
Message=Could not load file or assembly 'Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Source=mscorlib
FileName=Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
If I run client program in non remoting then it works fine.(In non remoting mode I am directly taking session from shared lib in client application and then calling resp. function)

Also in remoting mode if I make call like SelectWithClassDialog("test", null, "test_str");

then it works fine.
So I think problem is with callback in remoting mode.
Can anybody help how to use SelectWithClassDialog("test", ip, "test_str"); in remoting mode with callback.
I am new to c# and stuck at this point,would appreciate any help.Thanks in advance.