Click here to Skip to main content
15,887,267 members
Home / Discussions / C#
   

C#

 
QuestionC# Pin
Member 1068292828-Mar-14 7:42
Member 1068292828-Mar-14 7:42 
AnswerRe: C# Pin
Richard MacCutchan28-Mar-14 8:07
mveRichard MacCutchan28-Mar-14 8:07 
AnswerRe: C# Pin
PIEBALDconsult28-Mar-14 8:19
mvePIEBALDconsult28-Mar-14 8:19 
GeneralRe: C# Pin
thatraja30-Mar-14 23:34
professionalthatraja30-Mar-14 23:34 
AnswerRe: C# Pin
Dave Kreskowiak28-Mar-14 9:38
mveDave Kreskowiak28-Mar-14 9:38 
GeneralRe: C# Pin
PIEBALDconsult31-Mar-14 3:48
mvePIEBALDconsult31-Mar-14 3:48 
GeneralRe: C# Pin
Dave Kreskowiak31-Mar-14 4:46
mveDave Kreskowiak31-Mar-14 4:46 
QuestionHow to use callbacks in remoting in .Net(c#) Pin
smit_a28-Mar-14 2:58
smit_a28-Mar-14 2:58 
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.
AnswerRe: How to use callbacks in remoting in .Net(c#) Pin
alberich12328-Mar-14 3:24
alberich12328-Mar-14 3:24 
AnswerRe: How to use callbacks in remoting in .Net(c#) Pin
BobJanova31-Mar-14 0:46
BobJanova31-Mar-14 0:46 
GeneralRe: How to use callbacks in remoting in .Net(c#) Pin
smit_a1-Apr-14 1:00
smit_a1-Apr-14 1:00 
GeneralRe: How to use callbacks in remoting in .Net(c#) Pin
BobJanova1-Apr-14 1:20
BobJanova1-Apr-14 1:20 
QuestionHow to use TreeView for getting values from database in Sales form Pin
H@ck_N_Cr@ck27-Mar-14 21:18
H@ck_N_Cr@ck27-Mar-14 21:18 
AnswerRe: How to use TreeView for getting values from database in Sales form Pin
Richard MacCutchan28-Mar-14 0:24
mveRichard MacCutchan28-Mar-14 0:24 
QuestionC# Winform Application With MySql as Database Deployement Pin
ahmed_one27-Mar-14 19:34
ahmed_one27-Mar-14 19:34 
AnswerRe: C# Winform Application With MySql as Database Deployement Pin
V.28-Mar-14 0:37
professionalV.28-Mar-14 0:37 
GeneralRe: C# Winform Application With MySql as Database Deployement Pin
ahmed_one28-Mar-14 1:24
ahmed_one28-Mar-14 1:24 
GeneralRe: C# Winform Application With MySql as Database Deployement Pin
V.28-Mar-14 1:33
professionalV.28-Mar-14 1:33 
GeneralRe: C# Winform Application With MySql as Database Deployement Pin
ahmed_one28-Mar-14 1:42
ahmed_one28-Mar-14 1:42 
GeneralRe: C# Winform Application With MySql as Database Deployement Pin
V.28-Mar-14 2:12
professionalV.28-Mar-14 2:12 
GeneralRe: C# Winform Application With MySql as Database Deployement Pin
ahmed_one28-Mar-14 2:28
ahmed_one28-Mar-14 2:28 
GeneralRe: C# Winform Application With MySql as Database Deployement Pin
V.28-Mar-14 2:31
professionalV.28-Mar-14 2:31 
GeneralRe: C# Winform Application With MySql as Database Deployement Pin
ahmed_one28-Mar-14 2:49
ahmed_one28-Mar-14 2:49 
GeneralRe: C# Winform Application With MySql as Database Deployement Pin
V.28-Mar-14 2:57
professionalV.28-Mar-14 2:57 
GeneralRe: C# Winform Application With MySql as Database Deployement Pin
ahmed_one28-Mar-14 3:02
ahmed_one28-Mar-14 3:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.