views:

67

answers:

2

Hi, 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

A: 

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.

JaredPar
A: 
'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
ElGringoGrande