Collections, [DataContract] and svcutil
between an Indigo service and client. I have the following test DataContract:
[DataContract]
public class Book
{
[DataMember]
public string Title;
[DataMember]
public string ISBN;
}
[DataContract]
[KnownType(typeof(Book))]
public class LibraryCatalog
{
[DataMember]
public string CatalogName;
[DataMember]
public Book[] Books;
[DataMember]
public List<Book> Books2;
[DataMember]
public IList<Book> Books3;
[DataMember]
public Hashtable Books4;
[DataMember]
public IDictionary Books5;
[DataMember]
public Dictionary<string, Book> Books6;
[DataMember]
public IDictionary<string, Book> Books7;
}
Using the September 2005 CTP toolset and svcutil, the generated proxy class
contains the following (my comments added):
// makes sense
private IndigoCollectionsTestServer.Book[] BooksField;
// works, but why isn't this a List<Book>?
private IndigoCollectionsTestServer.Book[] Books2Field;
// this is what I really want to use. Why is it only an object?
private object Books3Field;
// Make sense -- requires [KnownType(typeof(Book))] so client can cast
// types appropriately. I wonder why it's not an actual Hashtable
object?
private System.Collections.Generic.Dictionary<object, object>
Books4Field;
// Why isn't this an IDictionary object?
private object Books5Field;
// Makes sense. This is what I'd expect.
private System.Collections.Generic.Dictionary<string,
IndigoCollectionsTestServer.Book> Books6Field;
// Why isn't this like Books6, only with IDictionary<>?
private object Books7Field;
private string CatalogNameField;
Questions:
1) What's going on in the example above? Why are some strong types carried
through and not others? Is this because of bugs in the current tools, or is
this the intendend, documented behavior?
2) What best practices are you folks using to get strongly-typed collections
on both sides?
3) Is there [DataContract] documentation on how proxies are generated so I
don't have to resort to trial-and-error?
4) I'm using [DataContract] so that I can have good support for versioning
as the clients and service evolve independently. In my understanding, using
ISerializable or [Serializable] isn't a best practice for versioning. Is
this right?
5) Is any of the above related to a choice of serializer (XmlFormatter or
XmlSerializer)? XmlFormatter is preferred, from what I read.
TIA,
Galen
Galen Earl Murdock
Principal Software Developer
Veracity Solutions, Inc.

