0

I'm trying to send a class via WCF over basicHttpBinding that contains a Dictionary<byte, object> and inside it is a Hashtable - this is needed due to existing code requirements and it can not be changed.

Now if I send out a class with just a Dictionary<byte, object> or Hashtable it works like a charm, but when I send out a dictionary containing a Hashtable I get the following error message:

There was an error while trying to serialize parameter http://tempuri.org/:UpdateResult. The InnerException message was 'Type 'System.Collections.Hashtable' with data contract name 'ArrayOfKeyValueOfanyTypeanyType:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.

Now I've even tried adding all the "Service Known Type" attributes to my service interface, with no luck:

    [ServiceContract]
    public interface IServerProxy
    {
        [OperationContract]
        bool Connect(long FBUID, string SecretKey);

        [OperationContract]
        [ServiceKnownType(typeof(IDictionary<byte, Hashtable>))]
        [ServiceKnownType(typeof(IDictionary<Hashtable, Hashtable>))]
        [ServiceKnownType(typeof(IDictionary<object, object>))]
        [ServiceKnownType(typeof(IDictionary<object, IDictionary<object, object>>))]
        List<QueuedMessage> Update(long FBUID, string SecretKey);
    }

But to be perfectly honest, I've used that tag blindly without full understanding of what it does and how (and if) it can be used to help me.

So, anyone has any idea what I should do?

Thanks!

4

1 回答 1

1

请参阅我关于 wcf 中泛型的回答。泛型在 SOA 情况下是不可能的。这个问题提出了一个替代解决方案。希望这可以帮助

于 2012-05-11T14:51:26.037 回答