dotnet / wcf

This repo contains the client-oriented WCF libraries that enable applications built on .NET Core to communicate with WCF services.
MIT License
1.72k stars 558 forks source link

Emulator/Android crashes when clicking a button (connected WCF service with NET MAUI for database) #5548

Open Thobs-Tricks opened 6 months ago

Thobs-Tricks commented 6 months ago

Description

System.ServiceModel.CommunicationException
  Message=Connection failure
  Source=System.ServiceModel.Http
  StackTrace:
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(HttpRequestException requestException, HttpRequestMessage request, HttpAbortReason abortReason) in /_/src/System.ServiceModel.Http/src/System/ServiceModel/Channels/HttpChannelHelpers.cs:line 108
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpClientRequestChannel.HttpClientChannelAsyncRequest.<SendRequestAsync>d__13[[System.ServiceModel.Channels.IRequestChannel, System.ServiceModel.Primitives, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext() in /_/src/System.ServiceModel.Http/src/System/ServiceModel/Channels/HttpChannelFactory.cs:line 1076
   at System.ServiceModel.Channels.RequestChannel.RequestAsync(Message message, TimeSpan timeout) in /_/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/RequestChannel.cs:line 267
   at System.ServiceModel.Channels.RequestChannel.RequestAsyncInternal(Message message, TimeSpan timeout) in /_/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/RequestChannel.cs:line 238
   at System.Runtime.TaskHelpers.WaitForCompletionNoSpin[Message](Task`1 task) in /_/src/System.ServiceModel.Primitives/src/Internals/System/Runtime/TaskHelpers.cs:line 294
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) in /_/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/RequestChannel.cs:line 227
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) in /_/src/System.ServiceModel.Primitives/src/System/ServiceModel/Dispatcher/RequestChannelBinder.cs:line 107
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) in /_/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/ServiceChannel.cs:line 760
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) in /_/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/ServiceChannel.cs:line 717
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(MethodCall methodCall, ProxyOperationRuntime operation) in /_/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/ServiceChannelProxy.cs:line 390
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(MethodInfo targetMethod, Object[] args) in /_/src/System.ServiceModel.Primitives/src/System/ServiceModel/Channels/ServiceChannelProxy.cs:line 144
   at generatedProxy_1.Login(String , String )
   at ServiceReference1.Service1Client.Login(String username, String password) in C:\Users\shekg\OneDrive\Documents\2024 Academics\IFM03A3\Group Project\Project\team34App\Connected Services\ServiceReference1\Reference.cs:line 1613
   at team34App.LoginPage.OnLoginClicked(Object sender, EventArgs e) in C:\Users\shekg\OneDrive\Documents\2024 Academics\IFM03A3\Group Project\Project\team34App\Pages\LoginPage.xaml.cs:line 17
   at Microsoft.Maui.Controls.Button.Microsoft.Maui.Controls.Internals.IButtonElement.PropagateUpClicked() in D:\a\_work\1\s\src\Controls\src\Core\Button\Button.cs:line 275
   at Microsoft.Maui.Controls.ButtonElement.ElementClicked(VisualElement visualElement, IButtonElement ButtonElementManager) in D:\a\_work\1\s\src\Controls\src\Core\Button\ButtonElement.cs:line 40
   at Microsoft.Maui.Controls.Button.SendClicked() in D:\a\_work\1\s\src\Controls\src\Core\Button\Button.cs:line 250
   at Microsoft.Maui.Controls.Button.Microsoft.Maui.IButton.Clicked() in D:\a\_work\1\s\src\Controls\src\Core\Button\Button.cs:line 484
   at Microsoft.Maui.Handlers.ButtonHandler.OnClick(IButton button, View v) in D:\a\_work\1\s\src\Core\src\Handlers\Button\ButtonHandler.Android.cs:line 148
   at Microsoft.Maui.Handlers.ButtonHandler.ButtonClickListener.OnClick(View v) in D:\a\_work\1\s\src\Core\src\Handlers\Button\ButtonHandler.Android.cs:line 169
   at Android.Views.View.IOnClickListenerInvoker.n_OnClick_Landroid_view_View_(IntPtr jnienv, IntPtr native__this, IntPtr native_v) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.Views.View.cs:line 2374
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 125

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

8.0.40 SR5

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

github-actions[bot] commented 6 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

Eilon commented 6 months ago

Hi @Thobs-Tricks , are you saying that the whole emulator crashes? Or the app you wrote is crashing within the emulator?

Thobs-Tricks commented 6 months ago

The app i wrote crashes within emulator, when I click a button,

below is the code inside my .cs file

////////////////////

using team34App.Pages;

namespace team34App;

public partial class LoginPage : ContentPage
{
    ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();

    public LoginPage()
    {
        InitializeComponent();
    }

    private void OnLoginClicked(object sender, EventArgs e)
    {

        int lgn = sc.Login(enUser.Text.ToString(), enPass.Text.ToString());

        string usr = sc.GetUserType(lgn);

        if(lgn == 0) 
        {
            lblError.Text = "User Not Found/Eligible To Login";
        }else
        {
            Navigation.PushAsync(new HomePage(lgn));
        }
    }
}
drasticactions commented 6 months ago

Going by the stack trace, I believe this will either be a runtime bug, or an issue with your service. There's a connection issue with accessing your service and my guess is that if you deployed a .NET Android app without the MAUI UI Toolkit and ran that code, you would hit the same error.

@Eilon IMO I think this should be moved to runtime.

Thobs-Tricks commented 6 months ago

Well, I use the following link to connect the Service with the App.

http://localhost:57888/Service1.svc

The link works when I connect the Service with ASP .NET for web dev,

drasticactions commented 6 months ago

I don't doubt you have an issue; it's that based on that stack trace, your issue isn't a MAUI UI one, but a runtime issue. The underlying exception is in System.ServiceModel.Channels, and I'm willing to bet if you run your app using just .NET Android without the MAUI UI Toolkit, you'll hit the same exception. So I want to make sure, if this is indeed the issue, it goes to the correct location for it to be fixed, otherwise it will sit here and won't be touched.

Thobs-Tricks commented 6 months ago

ooh yeah, then please kindly move it to runtime issue slot,

moljac commented 6 months ago

@Thobs-Tricks Thanks for the feedback, but repro sample would help a lot to speed up investigations.

Try catching System.ServiceModel.CommunicationException and investigate details of the exception.

It does not look like MAUI exception, but:

  1. problems with with your WCF service
  2. problems with WCF
  3. problems with .NET for Android
  4. problems with runtime

From the runtime team (links below):

There are two workarounds that might apply in some scenarios:

  • disable compression in the Andorid client
  • add the following property to the .csproj file to switch from the AndroidMessageHandler to SocketsHttpHandler that decompresses the content correctly: <UseNativeHttpHandler>false</UseNativeHttpHandler>

Additional questions:

More details collected during investigating this issue:

thanks regards mel

dotnet-policy-service[bot] commented 6 months ago

Tagging subscribers to this area: @dotnet/area-system-threading-channels See info in area-owners.md if you want to be subscribed.

imcarolwang commented 6 months ago

I'm able to reproduce the issue, and it appears to be a problem with DNS resolution within the android emulator on my end. Everything works fine when I use the IP address for the WCF service.

Regarding the code snippet:

IPHostEntry hostEntry = Dns.GetHostEntry("service-host-name");

It throws the following error:

System.Net.Sockets.SocketException
  Message=hostname nor servname provided, or not known

So, this doesn't seem to be a problem with the WCF product.