You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fully implement ClientWebSocketOptions for .NET Core #15994
This type enables scenarios such as HTTP client cert, headers, cookies, credentials, proxy and WS sub-protocol specification.
@stephentoub I remember there is similar work required for the ManagedWebSocket implementation (proxy, etc). We may need to create an issue and review it for netstandard2.0.
We discussed this last week and decided to push it to Future.
We plan to replace WebSockets with ManagedWebSockets (which lack some other implementation that is currently supported).
It is too late to make it happen in 2.0 (we have higher priorities to finish and this is costly ~4w). We have it planned for 2.1 UWP (incl. beefing up ManagedWebSockets implementation) - at that moment it should be usable also for .NET Core.
@SidharthNabar, If I get it right, there is currently no way to get websocket client running behind a proxy server in net core?
@SidharthNabar is no longer working on the .NET Core project.
In terms of client websocket ability to navigate thru a proxy, I believe that it can thru the default system proxy. However, it will not be able to go thru a custom IWebProxy since it is not honoring the .Proxy property.
@davidsh I tried running a basic console app with this functionality and changed my system proxy to point to fiddler (127.0.0.1:8888) to capture all traffic flowing through the proxy. When I run the same setup on net46 target framework, I can see the traffic moving through the proxy (which are captured in fiddler). But when I change the target framework to netcoreapp2.0, the data is no longer captured in fiddler, which makes me believe the data isn't passing through the proxy. The entire connection + send + receive still works, but it just doesn't go through the proxy.
While debugging, I can see that in netcoreapp2.0, cws._innerWebSocket._webSocket is an object of type WinHttpWebSocket.
I'm running on Win10, VS 2017 15.3.3, and 2.0.0 dotnet core SDK version.
These are the two target frameworks: <TargetFrameworks>netcoreapp2.0</TargetFrameworks> <TargetFrameworks>net46</TargetFrameworks>
When I run this code under net46, I can see the data being captured in Fiddler (since fiddler listens on 127.0.0.1:8888) and system proxy is changed to the same endpoint. But the same code under netcoreapp2.0 doesn't go through the proxy endpoint.
The managed ClientWebSocket implementation as of dotnet/corefx#24288 now provides support for all of ClientWebSocketOptions, in that it passes all of the relevant options along to the ManagedHandler implementation.
@stephentoub Adding my CA to the list of trusted CA's on Linux got me this gem:
Unhandled Exception: System.Net.WebSockets.WebSocketException: The WebSocket client request requested '' protocol(s), but server is only accepting '' protocol(s).
at System.Net.WebSockets.WebSocketHandle.<ConnectAsyncCore>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Net.WebSockets.ClientWebSocket.<ConnectAsyncCore>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at CloudRunner.Program.<Main>d__0.MoveNext() in /home/fcarlier/git/CloudRunner/CloudRunner/Program.cs:line 111
--- End of stack trace from previous location where exception was thrown ---
at CloudRunner.Program.<Main>(String[] args)
The NuGet.org package is from the official release, 1.1 which was the last release that had a separate System.Net.WebSockets.Client NuGet package.
If you want daily feeds from MYGET.ORG, then your previous link would have been correct. However, we no longer build a separate System.Net.WebSockets.Client NuGet package. The new model starting with .NET Core 2.0 actually is for mega-packages. That is why the last date for that package is last January.
Instead of looking for the System.Net.WebSockets.Client.dll binary in a System.Net.WebSockets.Client NuGet package, you should look for that binary is one of the larger packages, i.e. NetCoreApp packages, etc.
I have a X509Certificate2 which represents certificate of the CA issuing the SSL certificates for the server, but I haven't been able to figure out yet how to let the ClientWebSocket know to either trust that CA or let me do the validation myself.
Is there a way for me to override the server certificate validation or pass a list of valid root certificates to ClientWebSocket?
Activity
CIPop commentedon Dec 13, 2016
@karelz, @davidsh this is tracking ClientWebSocketOptions work using WinHTTP on Windows.
This type enables scenarios such as HTTP client cert, headers, cookies, credentials, proxy and WS sub-protocol specification.
@stephentoub I remember there is similar work required for the ManagedWebSocket implementation (proxy, etc). We may need to create an issue and review it for netstandard2.0.
stephentoub commentedon Dec 13, 2016
The pieces not currently handled by ManagedWebSocket are listed here:
https://github.com/dotnet/corefx/blob/master/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs#L76-L80
the two main ones being proxy and credentials. Proxy should be pretty straightforward, I just never did it. Credentials will be harder.
CIPop commentedon Dec 13, 2016
I've opened dotnet/corefx#14480 to track the item. I'll submit a PR to change the code to point to the issue. (The TODO is missing the issue number.)
karelz commentedon Feb 2, 2017
We should consider it for 2.0 -- we should also find out if it is reasonable for us to reuse the ManagedWebSocket also on Windows.
karelz commentedon Apr 3, 2017
We discussed this last week and decided to push it to Future.
We plan to replace WebSockets with ManagedWebSockets (which lack some other implementation that is currently supported).
It is too late to make it happen in 2.0 (we have higher priorities to finish and this is costly ~4w). We have it planned for 2.1 UWP (incl. beefing up ManagedWebSockets implementation) - at that moment it should be usable also for .NET Core.
nemakam commentedon Sep 1, 2017
Just raising another request for this feature.
@SidharthNabar, If I get it right, there is currently no way to get websocket client running behind a proxy server in net core?
davidsh commentedon Sep 1, 2017
@nemakam
@SidharthNabar is no longer working on the .NET Core project.
In terms of client websocket ability to navigate thru a proxy, I believe that it can thru the default system proxy. However, it will not be able to go thru a custom IWebProxy since it is not honoring the .Proxy property.
nemakam commentedon Sep 1, 2017
@davidsh I tried running a basic console app with this functionality and changed my system proxy to point to fiddler (
127.0.0.1:8888) to capture all traffic flowing through the proxy. When I run the same setup onnet46target framework, I can see the traffic moving through the proxy (which are captured in fiddler). But when I change the target framework tonetcoreapp2.0, the data is no longer captured in fiddler, which makes me believe the data isn't passing through the proxy. The entire connection + send + receive still works, but it just doesn't go through the proxy.My code roughly looks like this
While debugging, I can see that in
netcoreapp2.0,cws._innerWebSocket._webSocketis an object of typeWinHttpWebSocket.I'm running on Win10, VS 2017 15.3.3, and 2.0.0 dotnet core SDK version.
nemakam commentedon Sep 2, 2017
For a repro, try this:
These are the two target frameworks:
<TargetFrameworks>netcoreapp2.0</TargetFrameworks><TargetFrameworks>net46</TargetFrameworks>When I run this code under
net46, I can see the data being captured in Fiddler (since fiddler listens on127.0.0.1:8888) and system proxy is changed to the same endpoint. But the same code undernetcoreapp2.0doesn't go through the proxy endpoint.stephentoub commentedon Oct 4, 2017
The managed ClientWebSocket implementation as of dotnet/corefx#24288 now provides support for all of ClientWebSocketOptions, in that it passes all of the relevant options along to the ManagedHandler implementation.
13 remaining items
qmfrederik commentedon Dec 1, 2017
@stephentoub Adding my CA to the list of trusted CA's on Linux got me this gem:
davidsh commentedon Dec 1, 2017
Go to NuGet.org:
https://www.nuget.org/packages/System.Net.WebSockets.Client/4.3.2
stephentoub commentedon Dec 1, 2017
Hmm, that error is coming from here:
https://github.com/dotnet/corefx/blob/baf2128a7cdf4a7638be1e86a6fc18651f3945d3/src/System.Net.WebSockets.Client/src/System/Net/WebSockets/WebSocketHandle.Managed.cs#L183
It's possible the validation condition there is wrong.
qmfrederik commentedon Dec 1, 2017
@davidsh Hmm, looks like that package is built off https://github.com/dotnet/corefx/commits/1503bfaac164addc2821b41193d2c54512d49e37 which doesn't seem to include dotnet/corefx#24288 though
davidsh commentedon Dec 1, 2017
The NuGet.org package is from the official release, 1.1 which was the last release that had a separate System.Net.WebSockets.Client NuGet package.
If you want daily feeds from MYGET.ORG, then your previous link would have been correct. However, we no longer build a separate System.Net.WebSockets.Client NuGet package. The new model starting with .NET Core 2.0 actually is for mega-packages. That is why the last date for that package is last January.
Instead of looking for the System.Net.WebSockets.Client.dll binary in a System.Net.WebSockets.Client NuGet package, you should look for that binary is one of the larger packages, i.e. NetCoreApp packages, etc.
@weshaggard can explain this further.
weshaggard commentedon Dec 1, 2017
As of 2.0 we ship this library in the Microsoft.NETCore.App packages which also contain ngen'ed binaries. However we do have our private corefx package https://dotnet.myget.org/F/dotnet-core/api/v2/package/runtime.linux-x64.Microsoft.Private.CoreFx.NETCoreApp/4.5.0-preview1-26001-02 which should contain the IL file for this. Give that a try.
As an aside @davidsh this fact is going to make fixing https://github.com/dotnet/corefx/issues/9503 more complicated
qmfrederik commentedon Dec 1, 2017
@stephentoub Yes, I think that validation condition needs tweaking. At least in my case,
subprotocolEnumerableValuescontained one empty string.Changing the condition to:
worked for me.
In other news, I got the managed implementation to work on Windows - thanks all who helped me, greatly appreciated! I'll keep you posted.
stephentoub commentedon Dec 1, 2017
Excellent.
qmfrederik commentedon Dec 10, 2017
@stephentoub I wanted to come back on this:
Is there a way for me to override the server certificate validation or pass a list of valid root certificates to
ClientWebSocket?stephentoub commentedon Dec 22, 2017
Not currently. Feel free to open an API proposal issue.
karelz commentedon Jan 12, 2018
We will be switching Windows WebSockets to managed WebSockets implementation in dotnet/corefx#9503, which already implements all
ClientWebSocketOptions(https://github.com/dotnet/corefx/issues/5120#issuecomment-334212032).Closing as duplicate of dotnet/corefx#9503.