C# 远程处理异常身份验证失败.net

C# 远程处理异常身份验证失败.net,c#,.net,remoting,C#,.net,Remoting,我一直在尝试在同一台pc上的组件之间进行远程通信,我遇到了一系列不同的异常,我真的不知道发生了什么,因为我很久没有使用远程通信了,也许你可以帮我一下 以下是异常的堆栈跟踪: System.Runtime.Remoting.RemotingException was unhandled Message=Authentication failure Source=mscorlib StackTrace: Server stack trace: at System.

我一直在尝试在同一台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: 
这是我用于远程处理服务器的代码:

以下是我为我的客户使用的代码:

这是被调用的工厂的代码:

谢谢大家,很抱歉,我没能让着色工作,这实际上是我在这里的第一个问题

driden.

更改ChannelServices.RegisterChannelchannel,false;至ChannelServices.RegisterChannelchannel,true;在远程处理服务器中。您的客户端要求提供安全通道,但服务器没有提供


您还可以删除RemotingConfiguration.RegisterWellKnown客户端类型FactoryPersistencia,tcp://localhost:8989/FabricaPersistencia; 来自您的客户。

您是将其用于新开发还是维护旧程序?而且它只包含在向后兼容的框架中。嗨,斯科特!谢谢你的回复。这实际上是大学的一个项目。这有点像一个社交网络,我被特别要求使用这项技术,尽管我已经老了。谢谢尼尔的建议。我现在得到这个异常:System.Runtime.Remoting.RemotingException:System.ArgumentNullException:调用DispatchChannelSink之前没有反序列化任何消息。由于字符限制,我无法粘贴整个stacktrace。我在这里仍然迷路。@driden做了IPUsuario ipus=fabricaPers.getfachadasuario;现在成功了吗?哪一行引发异常?公共类FactoryPersistencia:MarshallByRefObject{private static FactoryPersistencia instancia=null;private static HttpChannel chan;private FactoryPersistencia{chan=new-HttpChannel;ChannelServices.RegisterChannelchan,true;RemotingConfiguration.registerwellknown客户端类型的FactoryPersistencia,http://localhost:8585/FabricaPersistencia;}公共静态FactoryPersistencia getInstance{如果instancia==null instancia=new FactoryPersistencia;返回instancia;}哇,这不是格式化的,总之,我所做的是将通道更改为Http,并删除了一行I,其中我称为instancia=FactoryPersistenciaActivator.GetObjecttypeofFactoryPersistencia,http://localhost:8585/FabricaPersistencia;@driden在您的服务器中,您使用的是针对T的BinaryServerFormatterSinkProvidercp。将其更改为用于Http的SoapServerFormatterSinkProvider。在每个频道上也将ensureSecurity更改为false,除非您在IIS中托管。
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();
    }
}