RichardTheKiwi
RichardTheKiwi

Reputation: 107716

How to use .NET WebSocket Client with NTLM proxies?

My goal is to use a WebSocket .Net client implementation (i.e. not a browser) to connect to a WebSocket over a corporate proxy that requires NTLM authentication. So far, all the solutions (e.g. websocket-sharp-with-proxy, websocket4net) come up short.

I have tried these:

How to use proxies with the WebSocket4Net library

https://stackoverflow.com/a/2587330/573261

As far as I know, the author has not updated this discussion on adding NTLM proxy support. http://websocket4net.codeplex.com/discussions/448172

This question tried to ask why client implementations do not support proxies, but it was not answered, and did not shed any new light on why nobody wants to approach the problem.

So back to my question, how does one use WebSocket technology in a client app behind an NTLM proxy?

Upvotes: 11

Views: 5380

Answers (1)

Brandon Griffin
Brandon Griffin

Reputation: 348

The ClientWebSocket object found in System.Net.WebSockets contains an Options property which allows you to configure proxy settings.

var ws = new System.Net.WebSockets.ClientWebSocket();
await ws.ConnectAsync(new Uri("destination.com"), CancellationToken.None);
ws.Options.Proxy = new WebProxy("example.com")
{
    Credentials = new NetworkCredential("userName", "password")
};

The NetworkCredential object is used for password based authentication and may provide what you need. You can also try setting Credentials on the Options property of the WebSocket object like this if the above doesn't work.

ws.Options.Credentials = new NetworkCredential("userName", "password");

I do not have access to this type of environment, so I have not actually tried what you are trying to do and am not sure if this will help. But, this looks like it will work to me.

Upvotes: 3

Related Questions