2012-04-26 65 views
0

我正在使用Silverlight製作應用程序。在該應用程序,我增加一個Web服務,該網絡服務我有一個網頁的方法無法序列化System.Collections.IDictionary類型的成員System.Exception.Data,因爲它實現了IDictionary。

[WebMethod(Description = "Write buffer log")]  
     public bool WriteLog(System.Collections.ObjectModel.ObservableCollection<LogBuffer> buffer) 
     { 
      bool result = true; 
      .//Some code here 
      return result; 
     } 

但我得到的錯誤是「無法序列類型System.Collections.IDictionary成員System.Exception.Data,因爲它實現IDictionary的。「

其中日誌緩衝區類是

namespace WriterLog 
{ 
    [DataContract] 
    public class LogBuffer 
    { 
     [DataMember] 
     public string Message 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public Exception Exception 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public LogType LogType 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public string MethodName 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public string DeclaringType 
     { 
      get; 
      set; 
     } 
     [DataMember] 
     public DateTime LogTime 
     { 
      get; 
      set; 
     } 
    } 
} 

請幫助me.Thanks提前。

回答

0

的ObservableCollection Silverlight的版本是不可被序列化 http://msdn.microsoft.com/en-us/library/ms668604(v=vs.95).aspx

而是嘗試使用泛型列表。這裏的東西我使用和它的作品

[DataContractAttribute] 
public class InstrumentDataField : INotifyPropertyChanged 
    { 
    [DataMemberAttribute] 
    private string Value { get; set; } 

    [DataMemberAttribute] 
    public string Name { get; set; } 

    public InstrumentDataField(string field, string value) 
    { 
     this.Name = field; 
     this.Value = value; 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 

    public void NotifyPropertyChanged(string propertyName) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 
} 

使用

[OperationContract] 
public List<InstrumentDataField> GetInstrumentData(string browserid, long tickCount) 
{ 
    //some code here 
} 
+0

感謝答覆,但不是System.Collections.ObjectModel.ObservableCollection 我用System.Collections.Generic.List 但是還是我得到同樣的錯誤。 – Dany 2012-04-26 12:59:27

+0

there .. added a working sample – 2012-04-26 13:25:58

+0

請記住,Silverlight不喜歡普通的web服務等。有一個選項添加>>新>> Silverlight Webservice – 2012-04-26 13:27:29

相關問題