繁体   English   中英

外接程序VS2008中的.NET Remoting无法正常工作?

[英].NET Remoting in AddIn VS2008 not working?

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

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

但是我在AddIn类中尝试了它,它不起作用。 Connect()中使用时,它会引发“双端口占用”异常(也许插件在VS的两个实例中运行),因此我尝试将其移入一个称为函数的用户(工具箱菜单中的一个)。

但是,由于某种原因,我无法连接。 控制台应用程序使用完全相同的代码即可正常工作。 加载项是否在沙盒中运行并且倾向于“启动服务器”?

s

加载项不在沙盒中运行,因此这不是问题。 其他应用程序很可能会保留该端口。 或者您的connect方法被调用两次。 出于某些奇怪的启动原因,或者您的外接程序无提示地启动了两次。

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

'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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM