How do you code a Vb.net Remoting Service to listen to more then one TCP channel.

I have a Vb.net Service that I created that I want to be able to listen on multiple ports and have the different ports register to different classes in the same dll.  So, for example --- I want port 1 to register to objA.Class1 and port 2 to register to objA.Class2.  

This is an example of the code I am using that is located in the onstart method of the service:

TcpNotificationChannel = New TcpServerChannel(1)
ChannelServices.RegisterChannel(TcpNotificationChannel)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(objA.Class1), "Class1", WellKnownObjectMode.SingleCall)

TcpNotificationChannel = New TcpServerChannel(2)
ChannelServices.RegisterChannel(TcpNotificationChannel)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(objA.Class2), "Class2", WellKnownObjectMode.SingleCall)

If I do it this way I receive an error when I try to use the object for port 2.  I receive the error "Requested Service not found".  But when I use the object using port1 it works just fine.  If I switch the order in which they are registered with port 2 being first, the object for port 2 works fine and the call on the object for port 1 fails.

Anyone have any ideas?

Also note -- I plan on moving the registration to a configuration file, but was having problems unregistering the channels when using that approach.
VerbotenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ihenryCommented:
Try to give different name for each channel or pass empty string for channel name would do.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VerbotenAuthor Commented:
Thanks for the response from both of you...

I must appoligize, my sample code above is not the exact way I was doing it.  I had a bad case of cut and paste and forgot to change a few items.  Here is the way I am actually doing it:

dim TcpNotificationChannel1 as New TcpServerChannel(1)
ChannelServices.RegisterChannel(TcpNotificationChannel1)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(objA.Class1), "Class1", WellKnownObjectMode.SingleCall)

dim TcpNotificationChannel2 as New TcpServerChannel(2)
ChannelServices.RegisterChannel(TcpNotificationChannel2)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(objA.Class2), "Class2", WellKnownObjectMode.SingleCall)

So, I am currently using two different instances of the channel.  And I believe the Channel Names will be defaulted to empty string since I didn't set them.

Using the two channels works fine if both of them are registered to the same class, but the problem comes into play if two different classes are being used.  I realize that since my classes are both in the same object, I could used use an interface class that would implement both of them and that would work, but it doesn't seem like the correct or simpliest approach.

Another approach I thought of was using a seperate appdomain in the service, but that is an area I am very new to and currently don't know how to approach it.

Any other ideas?

Your help is appreciated!
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

ihenryCommented:

If I can remember correctly, ChannelName property is default to "tcp" if it's not set or set it explicitly to empty string to avoid name collition. Please check in MSDN help for TcpServerChannel and let me know if I'm correct.
0
ihenryCommented:

And how are you getting the object at client-side?
0
VerbotenAuthor Commented:
ihenry -- thanks for your help!

It looks like you are correct with the default name of a channel being "tcp".

While digging deeper, I found that the error "Only one usage of each socket address (protocol/network address/port) is normally permitted" was being generated at the service level and I didn't even realize it.  The error message I posted above was coming from the client side from the result of this problem.  I should have noticed that earlier :(

To fix the issue I changed to a different port for one of the channels and it is working fine now.  One thing I also did was to use the recommendation to uniquely name each of the channels during the declaration of the objects through the constructor.

Thanks again.
0
ihenryCommented:

You're welcome, glad your problem solved.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.