![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Default Port Number for a particular "Scheme"? Is there a .NET class where I can do something like this: int defaultPort = SomeDotNetClass.GetDefaultPort( Uri.UriSchemeHttps ); The Uri class is able to advise default port numbers for various schemes (but does not seem extensible) but I don't know whether they have been hard-coded or whether they have been pulled from somewhere else, and I would dearly like to avoid hard-coding 80, 443 etc in my application. Thanks Kevin |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Default Port Number for a particular "Scheme"? Kevin Frey wrote: Quote: > Is there a .NET class where I can do something like this: > > int defaultPort = SomeDotNetClass.GetDefaultPort( Uri.UriSchemeHttps ); > int defaultPort = new Uri(Uri.UriSchemeHttps + "://dummy").Port; Although this approach produces invalid URIs (for example, "mailto://dummy" isn't a valid URI as the mailto: scheme doesn't allow hierarchies and the "/" characters would need to be escaped to be part of a mailbox name), all the built-in parsers will accept this format as they all support hierarchies. Quote: > The Uri class is able to advise default port numbers for various schemes > (but does not seem extensible) default port with a new scheme. There is no way to simply associate a scheme with a port number without providing parsing capabilities, but there doesn't seem to be much use for that either. You could easily write your own class for this, though. Quote: > but I don't know whether they have been hard-coded or whether they have > been pulled from somewhere else, and I would dearly like to avoid > hard-coding 80, 443 etc in my application. > compare the effort required to make them changeable to the probability that they'll change within your application's lifetime it's obvious that it doesn't matter if you hard-code them. The solution I presented above is kludgy in that it might break down if you introduce custom parsers that don't allow hierarchies at all, so it has little advantage over simply putting in a const int HttpDefaultPort = 80; where needed. In this particular case, it's more important that people know what the magic number 80 means than that it's easy to change. The least redundant solution that's still guaranteed not to break is to write your own specific class to associate schemes with port numbers, but this will be divorced from the framework's own mapping. -- J. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Default Port Number for a particular "Scheme"? Thanks. I did consider the fact that the port numbers were codified in RFCs etc but it was still a question of elegance over whether I could avoid defining them myself. Given there appears only a kludgey way of getting the port numbers (in the sense that it appears less elegant than simply defining the port numbers as constants), I'll just go with the constant idea for now. Kevin. "Jeroen Mostert" <jmostert@xxxxxx> wrote in message news:4a0d4e6c$0$187$e4fe514c@xxxxxx Quote: > Kevin Frey wrote: Quote: >> Is there a .NET class where I can do something like this: >> >> int defaultPort = SomeDotNetClass.GetDefaultPort( Uri.UriSchemeHttps ); >> > > int defaultPort = new Uri(Uri.UriSchemeHttps + "://dummy").Port; > > Although this approach produces invalid URIs (for example, > "mailto://dummy" isn't a valid URI as the mailto: scheme doesn't allow > hierarchies and the "/" characters would need to be escaped to be part of > a mailbox name), all the built-in parsers will accept this format as they > all support hierarchies. > Quote: >> The Uri class is able to advise default port numbers for various schemes >> (but does not seem extensible) > You can derive a new UriParser and use UriParser.Register() to associate a > default port with a new scheme. There is no way to simply associate a > scheme with a port number without providing parsing capabilities, but > there doesn't seem to be much use for that either. You could easily write > your own class for this, though. > Quote: >> but I don't know whether they have been hard-coded or whether they have >> been pulled from somewhere else, and I would dearly like to avoid >> hard-coding 80, 443 etc in my application. >> > compare the effort required to make them changeable to the probability > that they'll change within your application's lifetime it's obvious that > it doesn't matter if you hard-code them. > > The solution I presented above is kludgy in that it might break down if > you introduce custom parsers that don't allow hierarchies at all, so it > has little advantage over simply putting in a > > const int HttpDefaultPort = 80; > > where needed. In this particular case, it's more important that people > know what the magic number 80 means than that it's easy to change. The > least redundant solution that's still guaranteed not to break is to write > your own specific class to associate schemes with port numbers, but this > will be divorced from the framework's own mapping. > > -- > J. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Number of "messages" not relating to actual number | Live Mail | |||
| Set the "No Sounds" scheme for the default user profile | Vista installation & setup | |||
| NOW WHAT? "The maximum number of secrets that may be stored in a single system has been exceeded" | Vista security | |||
| FTP Server - "FTP Port is used" error message" | .NET General | |||
| "the color scheme has been changed to windows vista basic" | Vista General | |||