Ciao ragazzi ecco qua il mio problema: sto implementando una chat (basata su console) composta da 3 oggetti principali:
-classe server singleton
-classe client (istanziata tante volte quanti sono gli utenti)
-classe servant che contiene la coda dei messaggi
la classe servant l'ho istanziata solo una volta nella classe server poichè tutti gli utenti devono vedere la medesima instanza della coda.
il problema è un errore a runtime nella classe server:
Codice PHP:
public class CAServer
{
public static Servant s = new Servant();
public static void Main()
{
TcpChannel tcpChan = new TcpChannel(10060);
ChannelServices.RegisterChannel(tcpChan);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Servant), "Singletons", WellKnownObjectMode.Singleton);
s = (Servant)Activator.CreateInstance(typeof(Servant), null, new object[] { new UrlAttribute("tcp://localhost:10061") }); [COLOR=red]ERRORE[/COLOR]
Console.WriteLine("Press enter to shutdown the server.");
Console.ReadLine();
}
public Servant getServant()
{
return s;
}
}
e questo è il tipo di errore:
Codice PHP:
System.Reflection.TargetInvocationException non è stata gestita
Message="Eccezione generata dalla destinazione di una chiamata."
Source="mscorlib"
StackTrace:
in System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
in System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
in System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
in System.Activator.CreateInstance(Type type, Boolean nonPublic)
in System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
in System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
in System.Activator.CreateInstance(Type type, Object[] args, Object[] activationAttributes)
in RemotingCAServer.CAServer.Main() in *********:riga 21
in System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
in System.Threading.ThreadHelper.ThreadStart_Context(Object state)
in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
in System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Net.Sockets.SocketException
Message="Impossibile stabilire la connessione. Rifiuto persistente del computer di destinazione 127.0.0.1:10061"
Source="mscorlib"
ErrorCode=10061
NativeErrorCode=10061
StackTrace:
Server stack trace:
in System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
in System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
in System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket(EndPoint ipEndPoint)
in System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket()
in System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortAndSid, Boolean openNew)
in System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
in System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
in System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
in System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
in System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
in System.Runtime.Remoting.Activation.IActivator.Activate(IConstructionCallMessage msg)
in System.Runtime.Remoting.Activation.LocalActivator.DoRemoteActivation(IConstructionCallMessage ctorMsg)
in System.Runtime.Remoting.Activation.LocalActivator.Activate(IConstructionCallMessage ctorMsg)
in System.Runtime.Remoting.Activation.AppDomainLevelActivator.Activate(IConstructionCallMessage ctorMsg)
in System.Runtime.Remoting.Messaging.ClientContextTerminatorSink.SyncProcessMessage(IMessage reqMsg)
in System.Runtime.Remoting.Activation.ActivationServices.Activate(RemotingProxy remProxy, IConstructionCallMessage ctorMsg)
in System.Runtime.Remoting.Proxies.RemotingProxy.InternalActivate(IConstructionCallMessage ctorMsg)
in System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(IMessage reqMsg)
in System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
in Servant..ctor()
InnerException:
spero di essere stato chiaro nell'esporre il problema...
in un altro esercizio finchè mi instanziavo la servant nel client non avevo nessun errore...
grazie mille