当前位置:编程学习 > C#/ASP.NET >>

高手帮我看看吧

当服务端启动正常,当启动客户端时就会出现下图的错误:




下面是错误信息:

未处理 System.ArgumentNullException
  Message="值不能为空。\r\n参数名: source"
  Source="mscorlib"
  ParamName="source"
  StackTrace:
       在 System.Runtime.InteropServices.Marshal.CopyToManaged(IntPtr source, Object destination, Int32 startIndex, Int32 length)
       在 System.Net.Sockets.AcceptOverlappedAsyncResult.PostCompletion(Int32 numBytes)
       在 System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
       在 System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

--------------------编程问答--------------------

//就这几行代码还找不到错误吗,
//看看参数传值,设置断点调试一下.
--------------------编程问答-------------------- 异常窗口把代码挡住了~看不到你那source在哪。。。 --------------------编程问答-------------------- Server.cs的代码:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;

namespace RemotingSamples 
{

    public class Server
{
public static int Main(string [] args) 
{

TcpChannel chan1 = new TcpChannel(8085);
HttpChannel chan2 = new HttpChannel(8086);

ChannelServices.RegisterChannel(chan1);
ChannelServices.RegisterChannel(chan2);


            //服务器端激活。
            RemotingConfiguration.RegisterWellKnownServiceType
                (
                typeof(HelloServer),
                "SayHello",
                WellKnownObjectMode.Singleton
                );

            //客户端激活
            //RemotingConfiguration.ApplicationName = "Hello";
            //RemotingConfiguration.RegisterActivatedServiceType(
            //    typeof(HelloServer));


System.Console.WriteLine("Press Enter key to exit");
System.Console.ReadLine();
return 0;
}

}
}


Client.cs的代码:
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels.Http;
using System.Runtime.Remoting.Activation;
using System.Runtime.Remoting.Lifetime;
using System.IO;

namespace RemotingSamples 
{
public class Client
{
        public static void Main(string[] args)
        {
            //使用TCP通道得到远程对象
            ChannelServices.RegisterChannel(new TcpChannel());

            HelloServer obj = (HelloServer)Activator.GetObject(
              typeof(RemotingSamples.HelloServer),
              "tcp://localhost:8085/SayHello");
            if (obj == null)
            {
                System.Console.WriteLine(
                    "Could not locate TCP server");
            }



            //object[] attrs = { new UrlAttribute("tcp://localhost:8085/Hello") };
            //HelloServer obj = (HelloServer)Activator.CreateInstance(typeof(HelloServer), null, attrs);

            ILease lease = (ILease)obj.GetLifetimeService();
            if (lease != null)
            {
                Console.WriteLine("Lease Configuration:");
                Console.WriteLine("InitialLeaseTime: " +
                    lease.InitialLeaseTime);
                Console.WriteLine("RenewOnCallTime: " +
                    lease.RenewOnCallTime);
                Console.WriteLine("SponsorshipTimeout: " +
                    lease.SponsorshipTimeout);
                Console.WriteLine(lease.CurrentLeaseTime);
            }

        }

}
}


HelloServer.cs的代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Lifetime;

namespace RemotingSamples
{
    public class HelloServer : MarshalByRefObject
    {
        public HelloServer()
        {
            Console.WriteLine("HelloServer activated");
        }
        public String HelloMethod(String name)
        {
            Console.WriteLine(
                "Server Hello.HelloMethod : {0}", name);
            return "Hi there " + name;
        }
    }
}
--------------------编程问答-------------------- return "Hi there " + name;


name 为何物??
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,