4
votes

Some requests from our Android app to a WCF service results in the following error:

System.Runtime.Serialization.SerializationException: There was an error deserializing the object of type xxx.SaveChangesCommand. '�rg�rden' contains invalid UTF8 bytes. ---> System.Xml.XmlException: '�rg�rden' contains invalid UTF8 bytes. ---> System.Text.DecoderFallbackException: Unable to translate bytes [E6] at index 0 from specified code page to Unicode.

at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index) at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index) at System.Text.DecoderFallbackBuffer.InternalFallback(Byte[] bytes, Byte* pBytes, Char*& chars) at System.Text.UTF8Encoding.FallbackInvalidByteSequence(Byte*& pSrc, Int32 ch, DecoderFallbackBuffer fallback, Char*& pTarget) at System.Text.UTF8Encoding.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, DecoderNLS baseDecoder) at System.Text.UTF8Encoding.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex) at System.Xml.XmlConverter.ToChars(Byte[] buffer, Int32 offset, Int32 count, Char[] chars, Int32 charOffset)

--- End of inner exception

stack trace --- at System.Xml.XmlConverter.ToChars(Byte[] buffer, Int32 offset, Int32 count, Char[] chars, Int32 charOffset) at System.Xml.XmlBufferReader.GetChars(Int32 offset, Int32 length, Char[] chars) at System.Xml.XmlBufferReader.GetString(Int32 offset, Int32 length) at System.Xml.ValueHandle.GetString() at System.Xml.XmlBaseReader.ReadContentAsString() at System.Xml.XmlBaseReader.ReadElementContentAsString() at ReadArrayOfstringFromJson(XmlReaderDelegator , XmlObjectSerializerReadContextComplexJson , XmlDictionaryString , XmlDictionaryString , CollectionDataContract ) at System.Runtime.Serialization.Json.JsonCollectionDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.JsonDataContract.ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns) at ReadSaveShoppingListChangesCommandFromJson(XmlReaderDelegator , XmlObjectSerializerReadContextComplexJson , XmlDictionaryString , XmlDictionaryString[] ) at System.Runtime.Serialization.Json.JsonClassDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.Json.JsonDataContract.ReadJsonValue(XmlReaderDelegator jsonReader, XmlObjectSerializerReadContextComplexJson context) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, Type declaredType, DataContract& dataContract) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns) at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName) at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver)

--- End of inner exception stack trace ---
at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver) at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName) at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

I have been looking for some similar cases and I found this link:
Configuring the .NET WCF UTF-8 deserializer to modify/discard non-shortest form chars instead of throwing an exception?
with a possible fix of the error with UTF-8 using non-shortest form - if this is the case here which it looks like to me.

But I don't see why this fix should be necessary, because as stated here:
https://blogs.oracle.com/CoreJavaTechTips/entry/the_overhaul_of_java_utf

The new UTF-8 charset implementation has been integrated in JDK7, Open JDK 6, JDK 6 update 11 and later, JDK5.0u17, and 1.4.2_19.

When I look at the request I see:

HTTP_USER_AGENT:Apache-HttpClient/UNAVAILABLE (java 1.4)

but the Android app is compiled with jdk1.7.0_13

How should I fix this problem?

1
Why wote down without a comment??Morten Holmgaard
I have this exact problem. Finding a fix has been a headache. Adding a bounty to get more attention.Behr
The string �rg�rden is a clue to where the problem is. I would use Fiddler to trace the response and figure out what's going on. You can configure Android to use Fiddler as a proxy and you'll be able to see the request and response. You'll need to test under HTTP because setting up HTTPS requires a trusted certificate and it doesn't always work.itsben
Additionaly to Fiddler, switch ON WCF tracing logs. See msdn.microsoft.com/en-us/library/ms751526.aspx and msdn.microsoft.com/en-us/library/ms733025.aspxMimas
I fixed it the easy way by changing to rest services with ServiceStackMorten Holmgaard

1 Answers

0
votes

I think the XML is not completly in UTF-8 format. See the '�rg�rden' kind of text might be in the other format that UTF-8. Like ISO 8859-1 or something.

So try to encode the text in UTF-8 and it might work :)