I have an application that uses WCF. It runs great on Mono 2.8.2 on Ubuntu and .NET 3.0 on Windows.
It decorates the WCF service contract with the 'ServiceKnownType' attribute, which points to a method returning the derived types needed to use the server:
[ServiceKnownType("GetKnownTypes", typeof(KnownTypeProvider)]
I am porting my app to MonoTouch. I am using the latest 4.0, based on Mono 2.10.1. This no longer works: my WCF call fai开发者_运维问答ls because the DataContractSerializer on the client doesn't recognise the return type.
I set a breakpoint in my 'GetKnownTypes' method and see that it is never called. I assume that this part of System.ServiceModel is not present / not working in MonoTouch?
I try to work around this by decorating the base return type with the 'KnownType' attribute instead.
[KnownType("GetKnownTypes")]
Again, it doesn't work and my 'GetKnownTypes' method is never called. Looking at the source for DataContractSerializer, it seems if you use a method name rather than specifying the type, it just gets ignored?!
I will try again by specifying the type instead of using a method (looking at the source of DataContractSerializer, it looks like this will work), however this is tricky for me in MonoTouch because I will need to use typeof rather than Type.GetType("fully.qualified.typename").
Is there another solution? Workaround?
I did see this: How do you configure WCF known types programmatically?, however it seems MonoTouch is missing some of the required interfaces...
Thanks in advance
It looks firmly like either a bug in MonoTouch or a regression in Mono (I don't have an environment to test in Mono 2.10 on the desktop right now)
Worked around the issue by restructuring my projects and using
[KnownType(typeof(MyDerivedType))]
On the base type. This works just fine on MonoTouch 4.0.
精彩评论