dotnet remoting:
Hi,
I have a C# server working as a service using MarshalByRefObject
(
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT15.asp).
I only have one instance of the main server. This instance has a hashtable
containing my customers list. From an ASP.net web page, I call this server to
retreive that list, which is working fine.
However, I can't insert a new element. The weird thing is that the new
element is inserted but it desappear soon after.
Here's the configuration file for my server:
<configuration>
<system.runtime.remoting>
<application name="LiveSnapService">
<lifetime
leaseTime = "15M"
sponsorshipTimeOut = "10M"
renewOnCallTime = "15M"
pollTime = "10S" />
<service>
<wellknown type="LiveSnapDotNet.server.MainServer, LiveSnapDotNet"
objectUri="LiveSnapDotNet.server.MainServer"
mode="Singleton" />
</service>
<channels>
<channel ref="tcp" port="8085">
<serverProviders>
<formatter ref="binary" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>
In the MainServer class, I have a static method which is returning the main
server reference which I use to communicate with the remote server (it's
calling itself in a sense).
It goes like this:
public static MainServer Instance
{
get
{
MainServer mainServerRef = null;
try
{
// Checks if it's already registered
if (ChannelServices.RegisteredChannels.Length == 0)
{
BinaryServerFormatterSinkProvider srvFormatter = new
BinaryServerFormatterSinkProvider();
srvFormatter.TypeFilterLevel = TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clntFormatter =
new BinaryClientFormatterSinkProvider();
IDictionary props = new HashTable();
props["port"] = 0;
TcpChannel chan = new TcpChannel(props, clntFormatter, srvFormatter);
ChannelServices.RegisterChannel(chan);
}
// Creates the server reference.
mainServerRef = (MainServer)Activator.GetObject(
typeof(LiveSnapDotNet.server.MainServer),
"tcp://localhost:8085/LiveSnapDotNet.server.MainServer");
}
catch(Exception e)
{
}
return mainServerRef;
}
}
Then, if I get the customers list, it works:
mainServer = MainServer.Instance;
mainServer.CustomersList.Count; // Gives the correct number, let's say 2
But if I try to insert an element:
mainServer.CustomersList.add(1,new Customer());
mainServer.CustomersList.Count;
This gives the previous number, 2 while it is supposed to be 3.
I also created a new method update(customer c) that add the element and
return the updated hashtable. This time, by doing this, I got the updated
hashtable:
mainServer.CustomersList.update(new Customer()).Count // This gives 3
But right after, mainServer.CustomersList is still a the same point as
before with 2 elements.
Why is the client hashtable not updated?
Thanks,