Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Encryption Sink and multiple calls (Ingo please help)

0 views
Skip to first unread message

joe peavey

unread,
Jun 21, 2002, 12:48:15 PM6/21/02
to
Ingo:
 
My problem is that I need to implement your encryption sinks from chapter 9 for a TCP channel and I also need to have the ability to change the IP, port and url on the fly (from a config file). While I probably could get away with leaving the port and url static, the IP definitely has to change. Here's a snippet of the code:
RemotingConfiguration.Configure("C:\Config\TaskProcdll.dll.config")
If channelTCP Is Nothing Then
'taskProcEvents.WriteEntry("TaskSend: channeltcp is nothing")
    channelTCP = New TcpChannel(internalPort)
End If
tcpChannelIsRegistered = False
For Each Channel In ChannelServices.RegisteredChannels
    If Channel.ChannelName = channelTCP.ChannelName Then
        tcpChannelIsRegistered = True
        Exit For
    End If
Next
If Not tcpChannelIsRegistered Then ChannelServices.RegisterChannel(channelTCP)
taskReceiver = CType(Activator.GetObject(GetType(taskReceiver.TaskReceiver), _
"tcp://" & TargetIP & ":" & sendPort & "/" & sendURI), taskReceiver.TaskReceiver)
And here's the config file:
<configuration>
    <system.runtime.remoting>
        <application>
            <channels>
                <channel ref="tcp">
                    <clientProviders>
                        <formatter ref="binary" />
                        <provider type="EncryptionSink.EncryptionClientSinkProvider, EncryptionSink" algorithm="RC2" keyfile="c:\Config\key2.dat" />
                    </clientProviders>
                </channel>
            </channels>
        </application>
    </system.runtime.remoting>
</configuration>
The code is executing several times a minute (my test scenario runs it 100 times in less then a minute) and it may be called to run many times more then that. The error that I'm receiving is that on the second pass thru the code I get the error; "TCP channel is already registered", at the line "RemotingConfiguration.Configure("C:\Config\TaskProcdll.dll.config")." I'm also getting that the Key2.dat file is in use on the consecutive passes through the code.
Any ideas?
Some questions:
Is it possible to mix and match using config files and setting the values with Activator.GetType?
If not, how can I integrate the encryption sink with this process?
How long does the remoting process hang on to the Key file for the encryption? Any ideas on how to get it to release the lock on it?
 
What I've tried is to create the config file on the fly, changing the IP, port and url. This works for the first pass thru the code and then fails on consecutive passes. Here's the code:
 
    remoteConfig = "<configuration>" & vbCrLf & "<system.runtime.remoting>" & vbCrLf & _
        "<application>" & vbCrLf & "<channels>" & vbCrLf & "<channel ref=""tcp"">" & vbCrLf & _
        "<clientProviders>" & vbCrLf & "<formatter ref=""binary"" />" & vbCrLf & _
        "<provider type=""EncryptionSink.EncryptionClientSinkProvider, EncryptionSink"" algorithm=""RC2"" keyfile=""c:\Config\key2.dat"" />" & vbCrLf & _
       "</clientProviders>" & vbCrLf & "</channel>" & vbCrLf & "</channels>" & vbCrLf & "<client>" & vbCrLf & _
        "<wellknown type=""taskReceiver.TaskReceiver, TaskReceiver"" url=""tcp://" & TargetIP & ":" & sendPort & "/" & sendURI & """ />" & vbCrLf & _
    "</client>" & vbCrLf & "</application>" & vbCrLf & "</system.runtime.remoting>" & vbCrLf & "</configuration>"
configRemote = New FileStream("c:\Config\TaskProcdll.config", FileMode.Create, FileAccess.Write)
remoteSW = New StreamWriter(configRemote)
remoteSW.WriteLine(remoteConfig)
remoteSW.Flush()
remoteSW.Close()
configRemote.Close()
RemotingConfiguration.Configure("C:\Config\TaskProcdll.config")
What happens is that I'm still receiving the both errors; "TCP channel is already registered" and the key file is in use.
There are no other processes that use the key file.
Thx, any help would be appreciated
jp

Ingo Rammer

unread,
Jun 24, 2002, 2:37:50 AM6/24/02
to
Hi Joe,

as I know from your private emails, you already solved parts of this problem
so that I'll just answer the other questions.

> Any ideas? [...]


> Is it possible to mix and match using config files and setting
> the values with Activator.GetType?

Absolutely. And this would be exactly what I'd suggest. Define the channel -
including the custom sinks - in a configuration file but create all
references by using Activator.GetObject() or Activator.CreateInstance().
When doing it this way, your problem with reading the configuration file
multiple times will be solved because you can simply use different URLs in
your source code.

Actually, solving your problem by using a configuration file might be
possible as well but I guess it's way easier when using
Activator.GetInstance() in your case.

HTH,
-Ingo

Author of "Advanced .NET Remoting"
and "Advanced .NET Remoting in VB.NET"
http://www.dotnetremoting.cc

joe peavey

unread,
Jun 24, 2002, 2:18:52 PM6/24/02
to

Thx Ingo;

Perhaps you wouldn't mind looking at something else? I've taken your suggestion and the config file looks like this:

<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp">
<clientProviders>
<formatter ref="binary" />
<provider type="EncryptionSink.EncryptionClientSinkProvider, EncryptionSink" algorithm="RC2" keyfile="c:\Config\key2.dat" />
</clientProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
</
configuration>

 

and the code looks like this:

RemotingConfiguration
.Configure("C:\Config\TaskProcdll.dll.config")
taskReceive = CType(Activator.GetObject(GetType(TaskReceiver.TaskReceiver), _
"tcp://" &
TargetIP & ":" & sendPort & "/" & sendURI), TaskReceiver.TaskReceiver)
If Not taskReceive Is Nothing Then
If taskReceive.TaskReceive(msmqMessage.Body) Then
MessageBox.Show("TaskSend: sent task")
UpdateSqlStatus(xmlTask)
Else
MessageBox.Show("TaskSend: Send Task Failed")
End If
Else
MessageBox.Show("taskReciever is nothing, cannot process request")
End If

Everything appears to work correctly until you hit the line that calls the method on the remoted object:

If

taskReceive.TaskReceive(msmqMessage.Body) Then

which throws the error "FileNotFoundException" on it's assembly. I've properly referenced it. I am using the direct assembly, not an interface, I followed the sample apps from MS. The code works if I don't use the config file.

Any help would be greatly appreciated.

Thx

jp

"Ingo Rammer" <ram...@sycom.at> wrote in message news:#FWCOm0GCHA.1600@tkmsftngp13...> Hi Joe,
http://www.dotnetremoting.cc
>
>
>

joe peavey

unread,
Jun 24, 2002, 6:43:16 PM6/24/02
to
Nevermind, I worked it out myself. It was a combination of several things.
 
Thx for the help Ingo!
 
jp
"joe peavey" <jo...@cogenix.com> wrote in message news:#Oc2Lu6GCHA.1744@tkmsftngp13...
0 new messages