AddIn VS2008 中的 .NET Remoting 不起作用?

发布于 2024-08-05 07:18:21 字数 615 浏览 5 评论 0原文

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

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

但是我在 AddIn 类中尝试它,它不起作用。当在 Connect() 内部使用时,它会抛出“双端口占用”异常(也许该插件在 VS 的两个实例中运行),因此我尝试将其移动到一个名为用户的函数中(该函数位于工具箱菜单)。

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

奇斯

I just started with AddIn development and have a small problem. The following code is working nice inside a console application:

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

But I I try it in the AddIn class, it does not work. When used inside the Connect() it throws a "double port occupied" exception (perhaps the plugin was running in two instances of VS) so I tried moving it into a user called function (the one in the toolbox menue).

But still, for some reason I can't connect. Console App works fine with exactly the same code. Are AddIns running in a sandbox and a prohbited to "start servers"?

Chis

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只是偏爱你 2024-08-12 07:18:21

插件不在沙箱中运行,因此这不应该是问题。更有可能的是其他一些应用程序正在占用该端口。或者您的 connect 方法被调用两次。要么是出于某种奇怪的启动原因,要么是您让插件默默启动了两次。

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

AddIns do not run in a sandbox so this should not be the issue. It's much more likely that some other application is holding onto that port. Or that your connect method is being called twice. Either for some weird startup reason or that you have the addin silently launching twice.

An effective way to track this down would be to put a MessageBox.Show line just above the creation of the TcpChannel. This will prevent your application from silently double binding to the port and hopefully allow you to track down if it's getting launched twice.

纵性 2024-08-12 07:18:21
'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
'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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文