I've been trying to get this remoting communication between my components (both on the same pc) and I got a bunch of different exceptions, I really have no clue what's going on since I haven't used remoting in a loong time, maybe you can give me a hand.
here's the stacktrace of the exception:
System.Runtime.Remoting.RemotingException was unhandled
Message=Authentication failure
Source=mscorlib
StackTrace:
Server stack trace:
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.CreateAuthenticatedStream(Stream netStream, String machinePortAndSid)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.CreateSocketHandler(Socket socket, SocketCache socketCache, String machinePortAndSid)
at System.Runtime.Remoting.Channels.SocketCache.CreateSocketHandler(Socket socket, String machineAndPort)
at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket(AddressFamily family)
at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket()
at System.Runtime.Remoting.Channels.RemoteConnection.GetSocket()
at System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortAndSid, Boolean openNew)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Persistencia.Factory.FactoryPersistencia.GetFachadaUsuario()
at ConsolaPrueba.Program.Main(String[] args) in D:\Dropbox\Proyecto final 2014\ConsolaRedSocial\ConsolaPrueba\Program.cs:line 28
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: System.IO.IOException
Message=Unable to read data from the transport connection: The connection was closed.
Source=System
StackTrace:
at System.Net.Security.NegoState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.NegotiateStream.AuthenticateAsClient(NetworkCredential credential, ChannelBinding binding, String targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
at System.Net.Security.NegotiateStream.AuthenticateAsClient(NetworkCredential credential, String targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.CreateAuthenticatedStream(Stream netStream, String machinePortAndSid)
InnerException:
this is the code I use for the Remoting server:
BinaryServerFormatterSinkProvider formatServ = new BinaryServerFormatterSinkProvider();
//propiedades nombre y puerto del servidor
IDictionary props = new Hashtable();
props["name"] = "Canal";
props["port"] = 8989;
try
{
TcpChannel channel = new TcpChannel(props, null, formatServ);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(FactoryPersistencia),
"FabricaPersistencia",
WellKnownObjectMode.Singleton
);
Console.WriteLine("Servidor de Remoting Levantado...");
Console.WriteLine("Presione una tecla para terminar.");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
Here's the code I used for my client:
TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan, true);
RemotingConfiguration.RegisterWellKnownClientType(typeof(FactoryPersistencia), "tcp://localhost:8989/FabricaPersistencia");
FactoryPersistencia fabricaPers = FactoryPersistencia.getInstance();
IPUsuario ipus = fabricaPers.GetFachadaUsuario();
And here's the code to the Factory that's being called:
public class FactoryPersistencia : MarshalByRefObject
{
//Singleton
private static FactoryPersistencia instancia = null;
public static FactoryPersistencia getInstance(){
if (instancia == null)
instancia = (FactoryPersistencia)Activator.GetObject(typeof(FactoryPersistencia), "tcp://localhost:8989/FabricaPersistencia");
return instancia;
}
public IPUsuario GetFachadaUsuario()
{
return new PersistenciaUsuario();
}
public IPEvento GetFachadaEvento() {
return new PersistenciaEvento();
}
public IPAmistad GetFachadaAmistad()
{
return new PersistenciaAmistad();
}
}
Thanks everyone and I'm sorry I couldn't get the colouring to work, this is actually my first question here.
driden.
Change ChannelServices.RegisterChannel(channel, false);
to ChannelServices.RegisterChannel(channel, true);
in your remoting server. Your client is asking for a secure channel but the server isn't providing one.
You can also remove RemotingConfiguration.RegisterWellKnownClientType(typeof(FactoryPersistencia), "tcp://localhost:8989/FabricaPersistencia");
from your client.