Aim
To dynamically expose an RSS/Atom endpoint for a service that has an unknown enumerable type. The type will be found via reflection to build the syndication endpoint(s).
Approach
I am using .net 4.0
I am reflecting over a dll to expose endpoints, ie json, xml, soap. That all works as I want it to. (I am thus, using code to configure my WCF setup).
I am now trying to expose an rss endpoint for all ICollection found via reflection exposed via my services so that I can expose a SyndicationFeed for each method returning an ICollection.
I believe that I want to use a datascontractsurrogate, and have followed what msdn has to add on this. I have hooked up my datacontractsurrogate and I have observed that it is hitting my debug points inside of the surrogate.
I am getting the following exception from the svclog viewer:
Exception Type:
System.Runtime.Serialization.InvalidDataContractException, System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message:
Using surrogates with get-only collection properties is not supported. Consider removing the surrogate associated with 'System.Collections.Generic.Dictionary`2[[System.Xml.XmlQualifiedName, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.
Questions
- Conceptually what are my options for achieving what I want to acheive?
- Can I keep a type safe way of outputting a SyndicationFeed type rather than opting to write adhoc to an xml string?
Why are you surrogating Dictionary, though? I do not understand why your method, for example, does not just return an Object or even just ICollection as is, so you polymorphically return whatever object you want using whatever DLL type you want.
Without knowing this scenario further, I want to recommend that you also try the DataContractResolver. See this blog post, this sample, and the MSDN page to get started. It essentially helps you map one type to a different xsi:type representation on the wire, which might be all you want.
Are you sure you have exhausted all your options with respect to known types? See this blog post for a thorough treatment of the topic.