2011-06-16 23 views
3

我有一個WCF服務,我嘗試從我的客戶端發送一個Dictionary<CustomStruct, int>到我的服務器。我的WCF服務使用默認的BasicHttpBinding。詞典<struct,int>沒有正確序列化

當我將字典發送到服務器時,不會引發錯誤。但是,當我試圖循環通過我的詞典時,它是空的。

奇怪的是,Dictionary<string, string>實際上工作?!

是否有人知道爲什麼我的Dictionary<CustomStruct, int>在通過導線後爲空以及爲什麼Dictionary<string, string>有效。

[編輯] 這裏是我的結構看起來像:

[DataContract] 
public struct CustomStruct : IEquatable<CustomStruct> 
{ 
    [DataMember] 
    private string _prop; 

    public string Prop { get { return _prop; } } 

    public override int GetHashCode() 
    { 
     return Prop.GetHashCode(); 
    } 

    public static bool operator ==(CustomStruct left, CustomStruct right) 
    { 
     ... 
    } 

    public static bool operator !=(CustomStruct left, CustomStruct right) 
    { 
     ... 
    } 

    public override bool Equals(object obj) 
    { 
     ... 
    } 
} 
+0

'CustomStruct'的佈局是什麼? – linuxuser27 2011-06-16 15:25:43

+0

你可以發佈你的'CustomStruct'的代碼嗎?它是否標記爲「可序列化」? – 2011-06-16 15:26:41

+0

編輯我的原始文章 – 2011-06-16 15:30:40

回答

相關問題