我有一個Silverlight 3 UI訪問WCF服務,後者又訪問使用NHibernate的存儲庫。爲了克服一些NHibernate與WCF的延遲加載問題,我使用我自己的DataContract代理,如下所述:http://timvasil.com/blog14/post/2008/02/WCF-serialization-with-NHibernate.aspx。在這裏我設置preserveObjectReferences =真Silverlight WCF序列化DataContract(IsReference = true)問題
我的模型包含週期(即客戶用的IList [訂購])
當我取回從我服務的對象,它工作正常,但是當我嘗試發送相同對象回到WCF服務,我得到的錯誤:
System.ServiceModel.CommunicationException was unhandled by user code Message=There was an error while trying to serialize parameter http://tempuri.org/:searchCriteria . The InnerException message was 'Object graph ...' contains cycles and cannot be serialized if references are not tracked. Consider using the DataContractAttribute with the IsReference property set to true.'
所以循環引用現在在Silverlight中的一個問題,所以我嘗試改變我的DataContract是[DataContract(IsReference =真)],但現在當我嘗試從我的服務檢索一個對象我收到以下異常:
System.ExecutionEngineException was unhandled Message=Exception of type 'System.ExecutionEngineException' was thrown. InnerException:
任何想法?
我的數據合同是在客戶端和服務器之間共享的,所以是兩個都有IsReference = true。 我已經在服務器端應用自定義行爲並設置preserveObjectReferences = true。 但是在Silverlight 3中,不能設置preserveObjectReferences = true(沒有構造函數重載並且有一個私有setter)。 它可能與在.net 4.0中修復的此錯誤(http://connect.microsoft.com/VisualStudio/feedback/details/391260/executionengineexception-thrown-from-datacontractserializer-with-ilist-t)有關,但是我不確定是否可以升級到SL 4,但是依賴關係 – 2010-04-21 11:34:04
注意:從wcf服務獲取對象時,不會發生此錯誤,它會在將先前檢索到的對象發送回Silverlight客戶端的服務時發生 – 2010-04-21 11:39:13