簡體   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