Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NET远程处理:异常“;值为空";在RegisterWellKnown服务类型_C#_Remoting - Fatal编程技术网

C# .NET远程处理:异常“;值为空";在RegisterWellKnown服务类型

C# .NET远程处理:异常“;值为空";在RegisterWellKnown服务类型,c#,remoting,C#,Remoting,我是.NET远程处理和C#的新手。我需要一个客户机/服务器应用程序,并希望通过.NET远程处理来处理此问题。我已经为远程处理对象EchoServer类编写了一个类库,其中包含一些测试方法 我在VisualStudio中添加到服务器项目的类库。我还添加了程序集“System.Runtime.Remoting” 以下是我的服务器的代码: using System; using System.Collections.Generic; using Syst

我是.NET远程处理和C#的新手。我需要一个客户机/服务器应用程序,并希望通过.NET远程处理来处理此问题。我已经为远程处理对象EchoServer类编写了一个类库,其中包含一些测试方法

我在VisualStudio中添加到服务器项目的类库。我还添加了程序集“System.Runtime.Remoting”

以下是我的服务器的代码:

        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Linq;
        using System.Text;
        using System.Windows.Forms;
        using System.Runtime.Remoting;
        using System.Runtime.Remoting.Channels;
        using System.Runtime.Remoting.Channels.Tcp;
        using Remoting; //Namespace Lib

        namespace Server
         {
         public partial class Server : Form
{
    public Server()
    {
        InitializeComponent();

        TcpChannel serverChannel = null;

        try
        {
            serverChannel = new TcpChannel(9998);
            lvStatus.Items.Add("Server is listening on port 8089...");

            string strIn = "";

            ChannelServices.RegisterChannel(serverChannel, true);

            RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("Remoting.EchoServer, remoting_dll"), "Echo", WellKnownObjectMode.SingleCall);
        }
        catch (Exception ex)
        {
            ChannelServices.UnregisterChannel(serverChannel);
            MessageBox.Show(ex.Message.ToString());
        }
    }
}
}

如果启动服务器,将出现异常:

该值不能为NULL 参数名称:类型


我尝试过教程中的其他代码,但是如果远程处理对象的类作为类库实现,或者直接作为类在我的项目中实现,我会得到相同的结果。

您能发布远程处理的实现吗? 我想你的下一个错误是:

Remoting.EchoServer,Remoting\u dll

因此,您应该正确使用Type.GetType

工作代码示例:

static void Main(string[] args)
{
    Server();
}

static void Server()
{
    Console.WriteLine("Server started...");
    var httpChannel = new HttpChannel(9998);
    ChannelServices.RegisterChannel(httpChannel);
    RemotingConfiguration.RegisterWellKnownServiceType(Type.GetType("Server.Program+SomeClass"), "SomeClass", WellKnownObjectMode.SingleCall);
    Console.WriteLine("Press ENTER to quit");
    Console.ReadLine();
}

public interface ISomeInterface
{
    string GetString();
}

public class SomeClass : MarshalByRefObject, ISomeInterface
{
    public string GetString()
    {
        const string tempString = "ServerString";
        Console.WriteLine("Server string is sended: {0}", tempString);
        return tempString;
    }
}