Why there is no option to set the source (local) address for HttpWebRequest?

S

Sherif ElMetainy

Hello

I am writing a HTTP client, that will run on a computer with multiple IP
addresses. I want to bind the TCP socket for the HTTP connection to a
specific IP address, but unfortunately there is no option to do this in
System.Net.HttpWebRequest class. I looked for that option a lot, I even
looked at the ROTOR source code to if there is a private member that I can
access with reflection but didn't find anything. (I know this is not right
because internal implementation may change in the future, but I am
desperate)

I couldn't find HTTP clients for .NET that provide this option, and I have
no time to implement my own. I think this is a design flaw, that makes the
developer reimplement a whole set of classes in order to make such a minor
modification.

I suggest adding an event that it fired after the creation of the TCP socket
and before the connection is established so that the user can bind to a
localaddress or set other socket options, or even better a socket factory
class ( a class responsible for creating sockets for all connections
(HTTP/FTP/SMTP etc)) and a configuration option so that the user can provide
his/her own socket factory class.

Best regards,
Sherif
 
N

Nicholas Paldino [.NET/C# MVP]

Sherif,

Using an event for this kind of configuration would be a bigger design
flaw. You could have multiple event handlers vying for the configuration.
A better idea would be to provide an interface implementation which would
configure options.

If you want to make a suggestion, the best place to do it would be the
MSDN Product Feedback Home, located at:

http://lab.msdn.microsoft.com/productfeedback/default.aspx

You can input your request there, and if others see it, then they can
vote on it as well, and you can get some feedback from MS as well on the
issue.

Hope this helps.
 
S

Sherif ElMetainy

Thanks

I submitted a suggestion there

Best regards,
Sherif

Nicholas Paldino said:
Sherif,

Using an event for this kind of configuration would be a bigger design
flaw. You could have multiple event handlers vying for the configuration.
A better idea would be to provide an interface implementation which would
configure options.

If you want to make a suggestion, the best place to do it would be the
MSDN Product Feedback Home, located at:

http://lab.msdn.microsoft.com/productfeedback/default.aspx

You can input your request there, and if others see it, then they can
vote on it as well, and you can get some feedback from MS as well on the
issue.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Sherif ElMetainy said:
Hello

I am writing a HTTP client, that will run on a computer with multiple IP
addresses. I want to bind the TCP socket for the HTTP connection to a
specific IP address, but unfortunately there is no option to do this in
System.Net.HttpWebRequest class. I looked for that option a lot, I even
looked at the ROTOR source code to if there is a private member that I can
access with reflection but didn't find anything. (I know this is not right
because internal implementation may change in the future, but I am
desperate)

I couldn't find HTTP clients for .NET that provide this option, and I have
no time to implement my own. I think this is a design flaw, that makes the
developer reimplement a whole set of classes in order to make such a minor
modification.

I suggest adding an event that it fired after the creation of the TCP
socket
and before the connection is established so that the user can bind to a
localaddress or set other socket options, or even better a socket factory
class ( a class responsible for creating sockets for all connections
(HTTP/FTP/SMTP etc)) and a configuration option so that the user can
provide
his/her own socket factory class.

Best regards,
Sherif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top