我刚开始使用AddIn开发并遇到一个小问题。以下代码在控制台应用程序中运行良好:
Trace.WriteLine("Started");
var channel = new TcpChannel(8083);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject), "HelloWorld",
WellKnownObjectMode.Singleton);
但是我在AddIn类中尝试它,它不起作用。当在 Connect()中使用时,它会抛出“双端口占用”异常(也许插件在VS的两个实例中运行)所以我尝试将其移动到一个名为function的用户(在toolbox menue)。
但是,由于某些原因,我无法连接。 Console App与完全相同的代码一起工作正常。 AddIns是否在沙盒中运行并且是否可以“启动服务器”?
CHIS
答案 0 :(得分:0)
AddIns不在沙箱中运行,所以这不应该是问题。一些其他应用程序更有可能保留该端口。或者你的连接方法被调用两次。要么是因为一些奇怪的启动原因,要么是你有一个静音启动两次。
跟踪此问题的一种有效方法是将MessageBox.Show行放在TcpChannel创建的上方。这将阻止您的应用程序静默地双重绑定到端口,并希望您可以跟踪它是否已启动两次。
答案 1 :(得分:0)
'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