all groups > dotnet distributed apps > november 2004 >
You're in the

dotnet distributed apps

group:

Remoting configuration file for two objects.


Remoting configuration file for two objects. David
11/2/2004 12:05:01 PM
dotnet distributed apps: I have created some remoting applications, and they work just fine, and all
appeared well, until I decided to combine the functions from two applications
into a single service.

So, what I have is two remotable objects. Both of them are hosted in a
single Windows service. I need a channel, then, for each of them. (I do,
don't I? Even if I don't absolutely have to do it that way, I would rather do
it that way, because on the client side, the client code knows which ports to
look for them on.)

The myservice.exe.config file has a <channels> element that looks like this.

<channels>
<channel displayname="tcpchannel1"
type="System.Runtime.Remoting.Channels.Tcp.TcpChannel,
System.Runtime.Remoting, Version= (etc)... port=19543"
<ServerProviders> (etc) </serverProviders>
</channel>
<channel displayname="tcpchannel2"
type="System.Runtime.Remoting.Channels.Tcp.TcpChannel,
System.Runtime.Remoting, Version= (etc)... port=19542"
<ServerProviders> (etc) </serverProviders>
</channel>
</channels>

In other words, I want two TCP channels. One of them listens on 19542. The
other listens on 19543. These are the two ports I had used for each of my
previous applications, and the clients know to look for them.

When I run, though, I get an error. "The channel tcp is already registered".

Can I only have one tcp channel for a service? I can't have two on two
different ports? How do I do that. I have tried several variations on the
above, but nothing seems to work.

Re: Remoting configuration file for two objects. Sam Santiago
11/2/2004 12:19:04 PM
Add the id attribute for the channel element in your config file; here's an
example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gnconchanneltemplate.asp

Check out this link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemRuntimeRemotingChannelsChannelServicesClassRegisterChannelTopic.asp?frame=true

Here's an excerpt:
"Note You cannot register two channels with the same name in an
AppDomain. By default, the name of an HttpChannel is "http", and the name of
a TcpChannel is "tcp". Therefore, if you want to register two channels of
the same type, you must specify a different name for one of them through
configuration properties."

Thanks,

Sam
--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTechture.com
_______________________________
[quoted text, click to view]

Re: Remoting configuration file for two objects. David
11/2/2004 1:20:10 PM
Thanks, Sam. But I must be missing something, because it still doesn't work.

Previously, my <channels> element was in the <application> element. So,
when I added IDs, it informed me that I could only use the id attribute in a
channel template, which made sense. So, I created templates, and then the
actual channel declarations used ref="" statements, and I got the same
errors. I have tried a lot of variations on this theme, and get the same
results. Here is my current configuration file:


////////////////////////////////
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<channels>
<channel id="tcpchannel1" displayname="a"
type="System.Runtime.Remoting.Channels.Tcp.TcpChannel,
System.Runtime.Remoting, Version=1.0.5000.0, Culture=Neutral,
PublicKeyToken=b77a5c561934e089" port="19543">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"></formatter>
</serverProviders>
</channel>
<channel id="tcpchannel2" displayname="b"
type="System.Runtime.Remoting.Channels.Tcp.TcpChannel,
System.Runtime.Remoting, Version=1.0.5000.0, Culture=Neutral,
PublicKeyToken=b77a5c561934e089" port="19542">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
</channels>


<application>
<channels>
<channel ref="tcpchannel1" port="19543"></channel>
<channel ref="tcpchannel2" port="19542"></channel>
</channels>

</application>
</system.runtime.remoting>
</configuration>

The result is always an exception that says "The channel tcp is already
registered at
System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel"


I haven't seen any examples in the Microsoft literature where two different
tcp channels are registered at two different ports. Surely I can't be the
only one trying to do this. Usually, when I am trying to do something that I
can't find anyone who has done something similar, I find that I have a
fundamental misunderstanding of how things work. Is that what has happened
here?

[quoted text, click to view]
Re: Remoting configuration file for two objects. Sam Santiago
11/2/2004 2:30:03 PM
Sorry, it was the name attribute not the id attribute. Why did you want 2
channels anyway? Each channel services the entire AppDomain, so what do you
think you'll be gaining with 2 channels? Here's an example config file
using HTTP:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="SAOHost">
<service>
<wellknown mode="Singleton" type="SAOFactory.ObjectPublisher, SAOFactory"
objectUri="ObjectPublisher" />
<wellknown mode="Singleton" type="SAOFactory.MySharedObject, SAOFactory"
objectUri="MySharedObject" />
</service>
<channels>
<channel ref="http" port="8085" name="http1">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
<channel ref="http" port="8086" name="http2">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</configuration>

Thanks,

Sam
--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTechture.com
_______________________________
[quoted text, click to view]

RE: Remoting configuration file for two objects. David
11/3/2004 6:16:01 AM
Thanks, Sam.

I added the name attribute, and the program worked. (At least, it got
configured correctly. Now on to the actual functionality.)

Where the heck did the "name" attribute come from? I couldn't find it in
any books I have, in any sample code (except yours) , or in the Visual Studio
MSDN help files.

Why use two channels? I was combining code from two previous applications
into a single service. Clients that used the other apps used two different
channels. The project is in an exploration/proof of concept phase right now.
When it is all done, I don't know how many different apps will actually
provide the various services, so I just thought it made sense to assign
different port numbers to each service, and put them into different apps
depending on what made sense.

[quoted text, click to view]
Re: Remoting configuration file for two objects. Sam Santiago
11/3/2004 6:30:47 AM
I have seen the name attribute in sample programs where the channels are
configured programmatically, such as this example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconChannelFormatterConfigurationProperties.asp

I haven't read anything regarding using multiple channels in an AppDomain in
regards of improving performance, etc., but if you are doing it to deal
with existing applications I can see that.

Thanks,

Sam

--
_______________________________
Sam Santiago
ssantiago@n0spam-SoftiTechture.com
http://www.SoftiTechture.com
_______________________________
[quoted text, click to view]

AddThis Social Bookmark Button