Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have application #1 that configures its remoting through the system.runtime.remoting element in its app1.exe.config file. Then I have application #2 that needs to know which port application #1 is currently using for its remoted object (since it can be changed externally). Application #2 knows where to find the app1.exe.config file and what elements will be there. It should be easy.
XML
<configuration>
  <system.runtime.remoting>
    <application name="XXXServer">
      <channels>
        <channel ref="tcp" port="12345">
          . . .
        </channel>
      </channels>
      . . .
    </application>
  </system.runtime.remoting>
</configuration>

The current approach for getting the port number is to read the config file with XDocument and drill down to the "channel" XElement. (There ought to be an easier way, but I haven't been able to find it.) Further, XDocument seems to always open the file for exclusive access. I need it to share read access so other readers can access the same data. (Again, there must be a way, probably with XmlReader, but I need help figuring that one out.)
 
None of my many searches for a clean way to get that information have turned up any prospects. Does one exist?
Posted

1 solution

I like your idea to find a clean way.

I would use the fact that the XML schema exists for configuration files, see: http://msdn.microsoft.com/en-us/library/1fk1t1t0.aspx[^].

Here you can find the idea on how to use the schema: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/976a2831-8d5b-4fba-8d21-025067697075/[^].

—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 26-Feb-11 10:22am    
Good advice, my 5
Sergey Alexandrovich Kryukov 26-Feb-11 13:38pm    
Thank you.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900