編輯:從我看到你還需要設置IsReference =在DataContractAttribute真實屬性,看和here
IsReference獲取或設置一個值,該值指示是否保留對象引用數據。 PreserveObjectReferences應該得到一個值,該值指定是否使用非標準XML結構來保存對象引用數據。
單不支持數據合同序列化,但由於此評論的人士告訴做,有做了一些工作:
([MonoTODO(「支持陣列;支持Serializable接口;支持SharedType;使用DataContractSurrogate」) ] - preserveObjectReferences表示輸出是否應該包含ms:Id。)
嘗試閱讀.NET Framework文檔中的Data Contract Serialization here,並將其與Mono中提供的源代碼進行比較,這將澄清事情。
也做同樣的其他System.Runtime.Serialization命名空間,從MSDN閱讀文檔,並與你Mono namespaces
在單對System.Runtime.Serialization命名空間的源代碼可有什麼比較here和DataContractSerializer的類源是here包含以下感興趣的東西:
// Three constructors with this property
public DataContractSerializer (Type type,
IEnumerable<Type> knownTypes,
int maxObjectsInGraph,
bool ignoreExtensionDataObject,
**bool preserveObjectReferences,**
IDataContractSurrogate dataContractSurrogate)
: this (type, knownTypes)
{
Initialize (maxObjectsInGraph,
ignoreExtensionDataObject,
**preserveObjectReferences,**
dataContractSurrogate);
}
public DataContractSerializer (Type type,
string rootName,
string rootNamespace,
IEnumerable<Type> knownTypes,
int maxObjectsInGraph,
bool ignoreExtensionDataObject,
**bool preserveObjectReferences,**
IDataContractSurrogate dataContractSurrogate)
: this (type, rootName, rootNamespace, knownTypes)
{
Initialize (maxObjectsInGraph,
ignoreExtensionDataObject,
**preserveObjectReferences,**
dataContractSurrogate);
}
public DataContractSerializer (Type type,
XmlDictionaryString rootName,
XmlDictionaryString rootNamespace,
IEnumerable<Type> knownTypes,
int maxObjectsInGraph,
bool ignoreExtensionDataObject,
**bool preserveObjectReferences,**
IDataContractSurrogate dataContractSurrogate)
: this (type, rootName, rootNamespace, knownTypes)
{
Initialize (maxObjectsInGraph,
ignoreExtensionDataObject,
**preserveObjectReferences,**
dataContractSurrogate);
}
//初始化()方法
void Initialize (
int maxObjectsInGraph,
bool ignoreExtensionDataObject,
bool preserveObjectReferences,
IDataContractSurrogate dataContractSurrogate)
{
if (maxObjectsInGraph < 0)
throw new ArgumentOutOfRangeException ("maxObjectsInGraph must not be negative.");
max_items = maxObjectsInGraph;
ignore_ext = ignoreExtensionDataObject;
preserve_refs = preserveObjectReferences;
surrogate = dataContractSurrogate;
PopulateTypes (Type.EmptyTypes);
}
//的preserveObjectReferences()屬性
public bool PreserveObjectReferences {
get { return preserve_refs; }
}
根據this:
**缺省對象的引用不保留由DataContractSerializer的; 多次引用的對象的值被序列化多次。如果對象是相互(循環)引用的一部分(例如循環鏈表),則在序列化期間拋出異常。
的DataContractSerializer可製成通過構建DataContractSerializer的**當傳遞true爲參數PreserveObjectReference保護對象的引用:
new DataContractSerializer(type, name, ns, knownTypes,
0x7FFF /*maxObjectsInGraph*/,
false/*ignoreExtensionDataObject*/,
true/*preserveObjectReferences*/,
null/*dataContractSurrogate*/);
我不能回答你的問題,但我會建議你試試你的代碼與最新的單聲道行李箱,看看它是否在那裏工作。 WCF自2.6以來已經修復了很多... – TheNextman 2010-07-19 13:27:41