11

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?

Community
  • 1
  • 1
RichardTheKiwi
  • 105,798
  • 26
  • 196
  • 262
  • what are you using for the underlying .NET http stack? Most windows stacks (e.g. WinInet, WinHTTP) will already support NTLM. – Adrien Aug 23 '16 at 20:16
  • @Adrien Something to the tune of `new WebSocket("ws://echo.websocket.org", origin: "http://example.com");` but that doesn't take an NTLM proxy as a parameter. The libraries I mentioned were also tried, and whatever they use internally – RichardTheKiwi Sep 06 '16 at 02:13
  • Could you mention if this is like a standalone service process or more like a desktop app that a person would be logged in and starting your app from their credentials? – Sql Surfer Sep 11 '16 at 16:25
  • A desktop app (portable, xcopy-like) – RichardTheKiwi Sep 12 '16 at 02:55

1 Answers1

3

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.

Brandon Griffin
  • 348
  • 1
  • 8