Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't connect to secure websocket(wss) with android 8 #8952

Closed
Lukas123798 opened this issue Jul 23, 2022 · 6 comments
Closed

Can't connect to secure websocket(wss) with android 8 #8952

Lukas123798 opened this issue Jul 23, 2022 · 6 comments
Labels
platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@Lukas123798
Copy link

Description

I cant connect to secure websocket(wss), it just writing Unable to connect to the remote server, to unsecure websocket(ws) i can connect with no problems.
When i used android 11 phone it works fine.
Also i tested a few different websocket libraries, but nothing works.
Code for connecting to websocket:

async Task StartWebSocketAsync()
        {                
                await ws.ConnectAsync(new Uri("wss://url?token=" + Token), t);      
                await Task.Factory.StartNew(async () =>
                {
                    while (true)
                    {
                        await ReadMessage();
                    }
                }, t, TaskCreationOptions.LongRunning, TaskScheduler.Default);
                SendMessageAsync(msg);
            }            
        }

And also methods to receive and send message

Steps to Reproduce

  1. Connect to a secure websocket with .NET MAUI APP on android phone with android version 8, or 5 also not working
    Tested on physical phone, not on the emulator.

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 8, 5

Did you find any workaround?

In xamarin, there is SSL/TLS implementation and HttpClient implementation option in project settings, but in .NET MAUI its not or i didnt found it
image

Relevant log output

No response

@Lukas123798 Lukas123798 added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jul 23, 2022
@jfversluis
Copy link
Member

If you create a Android app without .NET MAUI, does it reproduce then?

As for the workaround, in the dialog you're seeing, change the settings to what you want and then inspect the changes in your csproj file. You can copy those into your .NET MAUI csproj file and that should still work even if the dialog in the UI isn't there. Let us please know the result of both of these, thanks!

@jfversluis jfversluis added platform/android 🤖 s/needs-info Issue needs more info from the author and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jul 25, 2022
@ghost
Copy link

ghost commented Jul 25, 2022

Hi @Lukas123798. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Jul 25, 2022
@Lukas123798
Copy link
Author

Thanks for the reply.
It only dont work on .NET MAUI app.
In Xamarin app it works fine.
I copied this from xamarin project where secure websocket work on android 8.

<PropertyGroup Condition="$(TargetFramework.Contains('-android'))">
            <AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
            <AndroidTlsProvider></AndroidTlsProvider>
      </PropertyGroup>

But after i paste it in my .NET MAUI project file, when i run app it crash on startup.
Also tried this variations, but it also didnt work.

<AndroidHttpClientHandlerType>System.Net.Http.HttpClientHandler</AndroidHttpClientHandlerType>
<AndroidTlsProvider>legacy</AndroidTlsProvider>
<AndroidTlsProvider>btls</AndroidTlsProvider>

@Steven-L-42
Copy link

Steven-L-42 commented Aug 8, 2022

I have the same problem.

If i run my Maui project in Windows machine = works perfectly
but if i run Maui project on a Android Device = Code quit at ClientResponse and forward other code.

This is one of the important settings, why someone discard it?
Mobile App without SSL/TLS Settings? Who decide this?

Code that works on MAUI with Windows machine but not with Android:

RestClient restClient = new RestClient();
RestRequest restRequest = new RestRequest(GetUrl);
RestResponse restResponse = restClient.Get(restRequest);

using (DataTable dt = (DataTable)JsonConvert.DeserializeObject(restResponse.Content, (typeof(DataTable))))
{
   
    CultureInfo german = new CultureInfo("de-DE");
    firmen = (from DataRow row in dt.Rows
              select new FirmenKunden()
              {
                  Id_Terminliste = row["id_Terminliste"].ToString(),
                  Id_Firma = row["id_Firma"].ToString(),
                  Termin = Convert.ToDateTime(row["Termin"]).ToString("ddd'. 'dd'.'MM'.'yyyy' 'HH:mm", german),
                  TerminTagZahl = Convert.ToDateTime(row["Termin"]).ToString("dd"),
                  TerminUnFormatted = Convert.ToDateTime(row["Termin"]),
                  ServiceSafe = row["ServiceSafe"].ToString(),
                  Beschreibung = row["Beschreibung"].ToString(),
                  ServiceNr = row["ServiceNr"].ToString(),
                  MassnahmenNr = row["MassnahmenNr"].ToString(),
                  Servicestand = row["Servicestand"].ToString(),
                  Firma = row["Firma"].ToString(),
                  Strasse = row["Strasse"].ToString(),
                  Postleitzahl = row["Postleitzahl"].ToString(),
                  Ort = row["Stadt"].ToString(),
                  Vertragsbeginn = Convert.ToDateTime(row["Vertragsbeginn"]).ToString("ddd'. 'dd'.'MM'.'yyyy", german),
                  Vertragsende = Convert.ToDateTime(row["Vertragsende"]).ToString("ddd'. 'dd'.'MM'.'yyyy", german)

              }).ToList();



}

@Lukas123798
Copy link
Author

Lukas123798 commented Aug 13, 2022

@ShiiikK I created new thread, because i add more information to it and this thread seems little bit dead, so if you want you can contribute there, i will delete this thread in the near future. dotnet/runtime#83118

@Lukas123798
Copy link
Author

Moved to new issue dotnet/runtime#83118

@Lukas123798 Lukas123798 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants