dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22k stars 1.72k forks source link

Inconsistent content length calling WCF service #16957

Closed billreiss closed 1 year ago

billreiss commented 1 year ago

Description

After adding a Service Reference to a MAUI 8 app and calling it, this works fine on Windows and Android but iOS has an error:

The number of bytes available is inconsistent with the HTTP Content-Length header. There may have been a network error or the client may be sending invalid requests.

Steps to Reproduce

  1. Create a new .NET 8 MAUI app.
  2. Add a WCF service reference using the Add Service Reference menu item on the project node with url https://wcfservice120230813151432.azurewebsites.net/Service1.svc and choose all the defaults.
  3. Add logic to call the WCF service:
var client = new ServiceReference1.Service1Client(ServiceReference1.Service1Client.EndpointConfiguration.BasicHttpsBinding_IService1);
var result = await client.GetDataAsync(1);

On Windows and Android, this runs successfully. On iOS, it fails with the error in the issue description.

Link to public reproduction project repository

https://github.com/billreiss/maui_bugs/tree/main/16957/Maui8App2

Version with bug

8.0.0-preview.7.8842

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 16.4

Did you find any workaround?

No

Relevant log output

2023-08-23 13:06:14.037022-0400 Maui8App2[77784:11787746] System.ServiceModel.ProtocolException: The number of bytes available is inconsistent with the HTTP Content-Length header.  There may have been a network error or the client may be sending invalid requests.
2023-08-23 13:06:14.037148-0400 Maui8App2[77784:11787746]    at System.ServiceModel.Channels.HttpResponseMessageHelper.ReadBufferedMessageAsync(Task`1 inputStreamTask, TimeoutHelper timeoutHelper)
   at System.ServiceModel.Channels.HttpResponseMessageHelper.ParseIncomingResponse(TimeoutHelper timeoutHelper)
2023-08-23 13:06:14.037243-0400 Maui8App2[77784:11787746]    at System.ServiceModel.Channels.HttpChannelFactory`1.HttpClientRequestChannel.HttpClientChannelAsyncRequest.<ReceiveReplyAsync>d__17[[System.ServiceModel.Channels.IRequestChannel, System.Private.ServiceModel, Version=4.10.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()
2023-08-23 13:06:14.037316-0400 Maui8App2[77784:11787746]    at System.ServiceModel.Channels.RequestChannel.RequestAsync(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.RequestAsyncInternal(Message message, TimeSpan timeout)
2023-08-23 13:06:14.037396-0400 Maui8App2[77784:11787746]    at System.Runtime.AsyncResult.End[SendAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
2023-08-23 13:06:14.037484-0400 Maui8App2[77784:11787746]    at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.<CreateGenericTask>b__0(IAsyncResult asyncResult)
--- End of stack trace from previous location ---
2023-08-23 13:06:14.037538-0400 Maui8App2[77784:11787746]    at Maui8App2.MainPage.CounterBtn_Clicked(Object sender, EventArgs e) in C:\repos\Medtronic\HeightAndScrollIssue\Maui8App2\Maui8App2\MainPage.xaml.cs:line 15
ghost commented 1 year ago

Hi @billreiss. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

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.

billreiss commented 1 year ago

Hi @billreiss. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

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.

I have added a repro at https://github.com/billreiss/maui_bugs/tree/main/16957/Maui8App2 using the steps I outlined above. Click the button to send a WCF request, it will succeed on Windows and Android and fail on iOS.

Eilon commented 1 year ago

@billreiss - this seems quite bizarre. Given that it's using HTTPS, there's either a problem in the service itself (seems unlikely), or perhaps in how the client code is interpreting the request. If I had to guess, this issue is either with WCF (pinging @imcarolwang - any clue?) or with the .NET networking libraries on iOS (@rolfbjarne - thoughts?).

rolfbjarne commented 1 year ago

or with the .NET networking libraries on iOS (@rolfbjarne - thoughts?)

Does it work if you set UseNativeHttpHandler=false in the project file?

<PropertyGroup>
    <UseNativeHttpHandler>false</UseNativeHttpHandler>
</PropertyGroup>
ghost commented 1 year ago

Hi @billreiss. 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 commented 1 year ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

XamlTest commented 1 year ago

Verified this on Visual Studio Enterprise 17.8.0 Preview 1.0. Repro on iOS 16.4 .NET 8, not repro on Windows 11 and Android 13.0-API33 with below Project: Maui8App2.zip

image

If set UseNativeHttpHandler=false in project file, works fine on iOS.

<PropertyGroup>
    <UseNativeHttpHandler>false</UseNativeHttpHandler>
</PropertyGroup>

image

rolfbjarne commented 1 year ago

OK, it looks like this is an issue in our NSUrlSessionHandler then, moving to xamarin/xamarin-macios.

rolfbjarne commented 1 year ago

This issue was moved to xamarin/xamarin-macios#18883