Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Call to a rest service with json with a content type format = raw results in InvalidCastException

$
0
0

Hi,

we have a set of services made available using a self-hosted .net application.

to make them available to mobile, we created a new rest/json endpoints, I used the following example ([blogs.msdn.com/b/carlosfigueira/archive/2011/05/03/wcf-extensibility-message-formatters.aspx](Carlos Figueira example - WCF extensibility message formatters)) as a baseline, because I wanted to use json.net and, in this example the body content is only serialized once (some examples converted the xml into json and changed body content serializing every object twice).

This example uses raw content format.

To set the content type mapper in .NET to RAW we set the content type mapper with the WebGttpBinding object, in mono I had to created a custom binding based on WebHttpBinding (the ContentTypeMapper property seems to be missing from the WebHttpBinding type in Mono).

Using the same code in mono and in .NET the results differ, in .NET everything works, in monodroid it throws an exception:

System.InvalidCastException: Cannot cast from source type to destination type. 07-24 16:47:05.686 I/MonoDroid( 2494): UNHANDLED EXCEPTION: System.InvalidCastException: Cannot cast from source type to destination type. 07-24 16:47:05.686 I/MonoDroid( 2494): at System.ServiceModel.Channels.WebMessageEncoder.WriteMessage (System.ServiceModel.Channels.Message message, System.IO.Stream stream) [0x00000] in :0 07-24 16:47:05.686 I/MonoDroid( 2494): UNHANDLED EXCEPTION: System.InvalidCastException: Cannot cast from source type to destination type.07-24 16:47:05.686 I/MonoDroid( 2494): at System.ServiceModel.Channels.HttpRequestChannel.BeginProcessRequest (System.ServiceModel.Channels.HttpChannelRequestAsyncResult result) [0x00000] in :0 07-24 16:47:05.686 I/MonoDroid( 2494): at System.ServiceModel.Channels.HttpRequestChannel.BeginRequest (System.ServiceModel.Channels.Message message, TimeSpan timeout, System.AsyncCallback callback, System.Object state) [0x00000] in :0 07-24 16:47:05.686 I/MonoDroid( 2494): at System.ServiceModel.Channels.HttpRequestChannel.Request (System.ServiceModel.Channels.Message message, TimeSpan timeout) [0x00000] in :0 07-24 16:47:05.686 I/MonoDroid( 2494): at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000] in :0 07-24 16:47:05.686 I/MonoDroid( 2494): at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (System.ServiceModel.Description.OperationDescription od, System.Object[] parameters) [0x00000] in :0 07-24 16:47:05.686 I/MonoDroid( 2494): at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x00000] in :0 07-24 16:47:05.686 I/MonoDroid( 2494): at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (System.Reflection.MethodBase method, System.String operationName, System.Object[] parameters) [0x00000] in :0 <

I know what an invalid cast is, but the error is being thrown inside the WriteMessage code, is this a mono problem?

I'm new at this mobile stuff, and I'm having some problems trying to understand the error, can anyone give me a hand to sort this out? -> If you guys have some suggestions that involve a simpler way to use json.net to encode the message, I'm open to suggestions.

Thanks,

Luis Pinho


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>