[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

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.
0
Verboten
Asked:
Verboten
  • 4
  • 2
1 Solution
 
ihenryCommented:
Try to give different name for each channel or pass empty string for channel name would do.
0
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now