Skip to content

[Android] Deserialization issue when consuming ASMX Web Service #80935

@steveisok

Description

@steveisok

Transferred customer issue from dotnet/android#7230

Description

I'm upgrading an existing Xamarin Traditional (Android) application into .NET 6 but I'm running into deserialization problems. Our Android app integrates with a .NET Framework 4.8 ASMX Web Service on the backend. This has been working fine for years but doesn't work after we move to .NET 6.

Reproduction Steps

I was able to create a repro project on my GitHub: https://github.com/adolfo1981/Net6AndroidWebServiceTest

My GitHub repro repo consists of the following projects:

  • HelloAndroid (NET6 - .net6.0-android Target Framework Moniker)
  • WebServiceServer (.NET Framework 4.8)
  • WebServiceClient (.NET 6) --> referenced by HelloAndroid project to consume ASMX Web Services
  1. Create a Xamarin Android (NET 6) project similar to @jamesmontemagno https://github.com/jamesmontemagno/net6-mobile-samples/tree/main/HelloAndroid
  2. Create a .NET Framework 4.8 WebServiceServer application following instructions like this: https://www.c-sharpcorner.com/article/how-to-create-a-web-service-project-in-net-using-visual-studio/
  3. Create a .NET 6 (Class Library) WebServiceClient and add a Connected Service -> Web Service pointing to a wsdl or deployed asmx file
  4. From Main Activity create an instance of the generated soap client and call HelloWorldAsync method:
var soapClient = new WebServiceSoapClient(WebServiceSoapClient.EndpointConfiguration.WebServiceSoap);
//Async test
var helloResponse = await soapClient.HelloWorldAsync();

Expected behavior

Get string response from HelloWorldAsync() method

Actual behavior

Exception:
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:HelloWorldResponse. The InnerException message was 'There was an error deserializing the object of type ServiceReference1.HelloWorldResponseBody. Unexpected end of file. Following elements are not closed: HelloWorldResult, HelloWorldResponse, Body, Envelope. Line 1, position 298.'. Please see InnerException for more details.

StackTrace:

at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)
   at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName)
   at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName)
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.PartInfo.ReadObject(XmlDictionaryReader reader, XmlObjectSerializer serializer) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Dispatcher/DataContractSerializerOperationFormatter.cs:line 657
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.PartInfo.ReadObject(XmlDictionaryReader reader) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Dispatcher/DataContractSerializerOperationFormatter.cs:line 652
   at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest) in /_/src/System.Private.ServiceModel/src/System/ServiceModel/Dispatcher/DataContractSerializerOperationFormatter.cs:line 521

Regression?

Yes, this worked in legacy Xamarin Android and should work in the .NET versions.

Known Workarounds

None

Configuration

.NET 6, .NET 7
Android (any architecture)

Other information

IMPORTANT:

The repro project points to my local IP (Bottom of Reference.cs file) and needs to be changed to IP of the user running the code. I could not use localhost because I was getting connectivity issues and only worked when setting my local IP.

Things that I've tried:

  • Generating the Web Service Client with 'Reuse referenced assemblies' enabled and disabled and that had no effect. Kept getting deserialization issue
  • Tried changing the HelloAndroid.csproj TargetFramework from .net6,0-android to .net6.0-android31.0 and nothing changed even after deleting /bin and /obj folders in this project

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions