.net remoting - excepcção

Machacaz

Power Member
Saudações.
Estou a fazer um trabalho para uma cadeira da escola.
Criei o meu servidor, este regista e cria o objecto remoto e tudo bem...
Acontece que queria, com um click num qualquer botão, desligar o objecto remoto (o servidor!)
Andei a pesquisar e até achei o que queria no site msdn mas obtenho uma excepcção..
Alguma ideia?

Aqui crio:

Código:
// Register our tcp channel
                txtbox.Text += " Register Channel . . . \n";
                TcpChannel ch = new TcpChannel(Convert.ToInt32(textBox1.Text));
                System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(ch, false);
                // registo do objecto
                RemotingConfiguration.RegisterWellKnownServiceType(
                    //tipo de objecto remoto
                    typeof(MssObject),
                    // URI - nome do objecto
                    "RemoteObject",
                    // tipo de chamada
                    WellKnownObjectMode.Singleton);

                //criar o objecto remoto
                RemoteObject = (MssObject)Activator.GetObject(typeof(MssObject),
                    "tcp://localhost:" + textBox1.Text + "/RemoteObject");

                //testar
                txtbox.Text += "\n remote say :" + RemoteObject.getState();

E com este código, obtenho uma excepção:

Código:
RemotingServices.Disconnect(RemoteObject);

Alguma ideia?
Obrigado desde já!
 
Realmente... ter falado num erro e não o ter dito... falha minha :S !
O erro que tenho, em forma resumida é: "Cannot call disconnect on a proxy."

Copiando os detalhes:
Código:
System.Runtime.Remoting.RemotingException was unhandled
  Message="Cannot call disconnect on a proxy."
  Source="mscorlib"
  StackTrace:
       at System.Runtime.Remoting.RemotingServices.Disconnect(MarshalByRefObject obj, Boolean bResetURI)
       at System.Runtime.Remoting.RemotingServices.Disconnect(MarshalByRefObject obj)
       at RemoteObject.ServerForm.button1_Click(Object sender, EventArgs e) in C:\Users\machacaz\Documents\IPT\IPT_2008_2009\1_semestre\sd\trab4_C#\zMsn\ServerSolution\ServerMsn\ServerForm.cs:line 69
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at RemoteObject.program.Main() in C:\Users\machacaz\Documents\IPT\IPT_2008_2009\1_semestre\sd\trab4_C#\zMsn\ServerSolution\ServerMsn\program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
 
O RemoteObject é uma proxy do servidor logo não podes desligá-lo. Um possível solução é criares um método remoto no servidor que o desliga, invocas esse método sobre a proxie e no servidor fazes disconnect ao objecto real. Digo eu que nunca trabalhei com .NET remoting.
 
Back
Topo