RemotingException身份验证失败.net

时间:2014-02-27 17:04:27

标签: c# .net remoting

我一直在尝试在我的组件之间进行远程通信(两者都在同一台PC上)并且我得到了许多不同的例外,我真的不知道发生了什么,因为我没有在龙中使用远程处理时间,也许你可以帮我一把。

这是异常的堆栈跟踪:

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: 

这是我用于远程服务器的代码:

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();
}

以下是我用于客户的代码:

TcpChannel chan = new TcpChannel();
ChannelServices.RegisterChannel(chan, true);
RemotingConfiguration.RegisterWellKnownClientType(typeof(FactoryPersistencia), "tcp://localhost:8989/FabricaPersistencia");

FactoryPersistencia fabricaPers = FactoryPersistencia.getInstance();


IPUsuario ipus = fabricaPers.GetFachadaUsuario();

以下是正在调用的工厂代码:

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();
    }
}

谢谢大家,我很抱歉我无法上色,这实际上是我的第一个问题。

driden。

1 个答案:

答案 0 :(得分:0)

将远程服务器中的ChannelServices.RegisterChannel(channel, false);更改为ChannelServices.RegisterChannel(channel, true);。您的客户端要求提供安全通道,但服务器未提供安全通道。

您也可以从客户端删除RemotingConfiguration.RegisterWellKnownClientType(typeof(FactoryPersistencia), "tcp://localhost:8989/FabricaPersistencia");