Skip to content

Fully implement ClientWebSocketOptions for .NET Core #15994

Closed

Description

@SidharthNabar

Currently, .NET Core has a placeholder implementation for ClientWebSocketOptions. Filing this issue to track the complete implementation.

Activity

  1. assigned and unassigned on Jun 1, 2016
  2. CIPop commented on Dec 13, 2016

    @CIPop
    Contributor

    @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.

  3. stephentoub commented on Dec 13, 2016

    @stephentoub
    Member

    I remember there is similar work required for the ManagedWebSocket implementation (proxy, etc).

    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.

  4. CIPop commented on Dec 13, 2016

    @CIPop
    Contributor

    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.)

  5. karelz commented on Feb 2, 2017

    @karelz
    Member

    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.

  6. karelz commented on Apr 3, 2017

    @karelz
    Member

    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.

  7. nemakam commented on Sep 1, 2017

    @nemakam

    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?

  8. davidsh commented on Sep 1, 2017

    @davidsh
    Contributor

    @nemakam

    @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.

  9. nemakam commented on Sep 1, 2017

    @nemakam

    @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.

    My code roughly looks like this

    ClientWebSocket cws = new ClientWebSocket();
    cws.Options.AddSubProtocol("amqp");
    Task task = cws.ConnectAsync(this.settings.Uri, CancellationToken.None).WithTimeout(timeout, () => "timeout");

    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.

  10. nemakam commented on Sep 2, 2017

    @nemakam

    For a repro, try this:

    public static async Task WsProxyTest()
    {
    	try
    	{
    		var uri = new Uri("wss://echo.websocket.org");
    		ClientWebSocket cws = new ClientWebSocket();
    		cws.Options.AddSubProtocol("amqp");
    		await cws.ConnectAsync(uri, CancellationToken.None);
    		await cws.SendAsync(new ArraySegment<byte>(new[] { (byte)65, (byte)66, (byte)67 }), WebSocketMessageType.Binary, true, CancellationToken.None);
    		var buffer = new ArraySegment<byte>(new byte[1000]);
    		await cws.ReceiveAsync(buffer, CancellationToken.None);
    		await cws.CloseAsync(WebSocketCloseStatus.NormalClosure, "close", CancellationToken.None);
    	}
    	catch (Exception e)
    	{
    		Console.WriteLine(e);
    	}
    }

    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.

  11. stephentoub commented on Oct 4, 2017

    @stephentoub
    Member

    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.

  12. 13 remaining items

  13. qmfrederik commented on Dec 1, 2017

    @qmfrederik
    Contributor

    @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)
    
  14. davidsh commented on Dec 1, 2017

    @davidsh
    Contributor
  15. stephentoub commented on Dec 1, 2017

    @stephentoub
    Member

    Adding my CA to the list of trusted CA's on Linux got me this gem

    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.

  16. qmfrederik commented on Dec 1, 2017

    @qmfrederik
    Contributor
  17. davidsh commented on Dec 1, 2017

    @davidsh
    Contributor

    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.

  18. weshaggard commented on Dec 1, 2017

    @weshaggard
    Member

    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

  19. qmfrederik commented on Dec 1, 2017

    @qmfrederik
    Contributor

    @stephentoub Yes, I think that validation condition needs tweaking. At least in my case, subprotocolEnumerableValues contained one empty string.

    Changing the condition to:

    if (subprotocolArray.Length != 1 ||
        (subprotocolArray[0] != string.Empty && (subprotocol = options.RequestedSubProtocols.Find(requested => string.Equals(requested, subprotocolArray[0], StringComparison.OrdinalIgnoreCase))) == null))
    

    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.

  20. stephentoub commented on Dec 1, 2017

    @stephentoub
    Member

    In other news, I got the managed implementation to work on Windows - thanks all who helped me, greatly appreciated! I'll keep you posted.

    Excellent.

  21. qmfrederik commented on Dec 10, 2017

    @qmfrederik
    Contributor

    @stephentoub I wanted to come back on this:

    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?

  22. stephentoub commented on Dec 22, 2017

    @stephentoub
    Member

    Is there a way for me to override the server certificate validation or pass a list of valid root certificates to ClientWebSocket?

    Not currently. Feel free to open an API proposal issue.

  23. karelz commented on Jan 12, 2018

    @karelz
    Member

    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.

  24. transferred this issue fromdotnet/corefxon Jan 31, 2020
  25. added this to the 2.1.0 milestone on Jan 31, 2020
  26. ghost locked as resolved and limited conversation to collaborators on Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Netenhancementos-windows

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions