The code shared on my blog works just fine; it's used in Fiddler, which is used by millions of people.
You should dump the entire port list and see what's going on; perhaps there's a problem in the value returned from context.Request.RemoteEndPoint.Port
.