Reputation: 49
Hell guys.
I am making this project with a Server, a Client and a Class library. In the class library (which I added to the Server and the Client as Reference), I have for example an:
string f = "not working";
public void SetString(string n)
{
f = n;
}
public string GetStr ()
{
return f;
}
I have connected the client and the server and they are working properly, also the Get method is working but the SET METHOD isn't working?? When I call the set method from the client, it doesn't set the value that I am giving!!. HttpChannel chan = new HttpChannel();
Tic obj = (Tic)Activator.GetObject(typeof(Tic), "http://127.0.0.1:9050/MyServer");
private void Form1_Load(object sender, EventArgs e)
{
ChannelServices.RegisterChannel(chan);
}
private void button1_Click(object sender, EventArgs e)
{
string m = "working";
obj.SetString(m);
}
Again i repeat that the Get Method is working properly, but only the Set Method... and the problem is that it doesn't show me any error!!! it is just not giving the value to the string variable!!
Upvotes: 0
Views: 1163
Reputation: 101
If I understand your set up correctly you are contacting a remote http server and calling a method which sets a variable value. You then contact that http server and ask for the value back, and you are getting the original value.
I'm not sure what sort of web "server" you are hosting but most of the time, servers only instantiate their classes when called upon. So basically you are contacting a server, it instantiates whatever class containing the "f" string. You set the value. The server completes its job and kills the process. Then you contact the server again asking for the value of "f", so it instantiates everything again, which means the value would be "not working".
Upvotes: 3
Reputation: 44068
Have you tried using Properties instead?
public class Foo
{
public string Message {get;set;}
}
public class Bar
{
public void Boz()
{
var foo = new Foo();
foo.Message = "Working";
}
}
Upvotes: 1