【问题标题】:.NET Remoting in AddIn VS2008 not working?AddIn VS2008 中的 .NET Remoting 不起作用?
【发布时间】:2009-09-18 11:16:55
【问题描述】:

我刚开始使用 AddIn 开发,遇到了一个小问题。以下代码在控制台应用程序中运行良好:

        Trace.WriteLine("Started");
        var channel = new TcpChannel(8083);
        ChannelServices.RegisterChannel(channel, false);
        RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "HelloWorld",
                                                           WellKnownObjectMode.Singleton);

但我在 AddIn 类中尝试过,它不起作用。当在 Connect() 中使用时,它会引发“双端口占用”异常(可能插件在两个 VS 实例中运行),所以我尝试将其移动到用户调用的函数中(在工具箱菜单)。

但是,由于某种原因,我仍然无法连接。控制台应用程序可以使用完全相同的代码正常工作。插件是否在沙盒中运行并禁止“启动服务器”?

Chis

【问题讨论】:

    标签: .net visual-studio remoting


    【解决方案1】:

    插件不在沙盒中运行,所以这应该不是问题。其他一些应用程序更有可能占用该端口。或者您的连接方法被调用了两次。要么是因为一些奇怪的启动原因,要么是你让插件静默启动了两次。

    跟踪此问题的有效方法是在 TcpChannel 的创建上方放置一个 MessageBox.Show 行。这将防止您的应用程序以静默方式双重绑定到端口,并希望您可以跟踪它是否启动了两次。

    【讨论】:

      【解决方案2】:
      'Check to see if the clint has already been Registered as a well known client on the server.
      
      Dim obj As WellKnownClientTypeEntry = RemotingConfiguration.IsWellKnownClientType(GetType([yourtype]))
      
      If obj Is Nothing Then 'ensure the wellknownclient hasn't been registered already
      
          If ChannelServices.GetChannel("HttpBinary") Is Nothing Then
      
          'The above check ensures that another object has not already registered the "HttpBinary" 
      
              Dim props As New Hashtable
      
              props("name") = "HttpBinary"
      
      
              Dim formatter As New BinaryClientFormatterSinkProvider
      
              Dim channel As New HttpChannel(props, formatter, Nothing)
              ChannelServices.RegisterChannel(channel, lvUsingSecure)
      
          End If
      
          RemotingConfiguration.RegisterWellKnownClientType(GetType([yourtype]), lvregisteredServer)
      
      End If
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-17
        • 1970-01-01
        • 2015-03-15
        • 2011-09-24
        相关资源
        最近更新 更多