开发者

Dictionary<struct,int> not serializing properly

开发者 https://www.devze.com 2023-03-13 06:28 出处:网络
I have a WCF service and I try to send a Dictionary<CustomStruct, int> from my client to my server. My WCF service use a default BasicHttpBinding.

I have a WCF service and I try to send a Dictionary<CustomStruct, int> from my client to my server. My WCF service use a default BasicHttpBinding.

When I send the Dictionary to the server, no error is thrown. But when I try to loop trough my Dictionary, it is empty.

The weird thing is that Dictionary<string, string> actually works ?!

Does someone have an idea of why my Dictionary<CustomStruct, int> is empty after it passes trough the wire and why Dictionary<string, string> works.

[EDIT] Here's how my struct looks like:

[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)
    {
开发者_Python百科        ...
    }

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

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


Here is a working sample that does what you want

http://rocksolidknowledge.blob.core.windows.net/demos/CustomStructSerialization.zip

Unfortunately from the code you have so far provided I can;t see what's wrong - at a guess you have different namespaces on your CustomStruct at client and service and so the serialization isn't working correctly but without seeing the generated code and the custom struct more fully i can't tell


Try to see if this FAQ help. WCF service returning an array of dictionary<string, object>

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号