I know this is not a GIS specific question but maybe you guys can answer it.
Our clients communicate to our GIS-Feature-Server via web services. On the server side we have implemented ThinkGeo-Layer classes to get the data from different data sources e.g. shapefile, database..... At the moment we copy the feature collection we get from ThinkGeo FeatureSource method GetFeaturesInsideBoundingBox() into a DataSet and deliver it via web service to our clients. At the client side we covert the data back from DataSet to feature collection. The time to convert feature collection to/from Dataset decreases our performance.
We tried to deliver the Feature-Collection as web service result but FeatureSourceColumn implements the IDictionary interface so the xml-serialization fails.
Is there a way I can serialize the Feature-Collection?
I think it’s possible to serialize the Feature-Collection, and I’m working on it to write a sample to test it, we will let you know the result as soon as it finished.
Yes, by default, XML Serialization does not serialize types that implement IDictionary; it throws an exception when you attempt to do so.
It’s a complex problem, but if you really want to do that, there is a solution:
Override XmlSerialization by making the type implement the System.Xml.Serialization.IXmlSerializable class. Define how you want the object to be serialized in XML in the WriteXml method, and define how you could recreate the object from an xml string in the ReadXml method.
Here is some code you can reference.
public void WriteXml(System.Xml.XmlWriter writer) { // Used while Serialization
// Serialize each BizEntity this collection holds foreach( string key in this.Dictionary.Keys ) { Serializer.Serialize(writer, this.Dictionary[key]); } }
public void ReadXml(System.Xml.XmlReader reader) { // Used while Deserialization
// Move past container reader.Read();
// Deserialize and add the BizEntitiy objects while( reader.NodeType != XmlNodeType.EndElement ) { BizEntity entity;
entity = Serializer.Deserialize(reader) as BizEntity; reader.MoveToContent(); this.Dictionary.Add(entity.Key, entity); } }
But this means you need deal with all logic, it has some complex, so just for your reference only.
after I while I come back to this issue. I deliberated on your suggestion but even if I can create my own serializable dictionary I have to wrap all features I get from ThinkGeo’s FeatureSource. This means I have to Wrap all Features by itterating through all features in the result collection. I have to do this on the server (wrap to serialize) and also on the client (unwrap to native ThinkGeo feature).
I think the best way to avoid performance issues is that you modify your feature structure to be serializable -> e.g. replace dictionary with a serializable type or implement your own dictionary that has implemented IXmlSerializable interface.