DataContract Known Types - passing array

Posted by Erup on Stack Overflow See other posts from Stack Overflow or by Erup
Published on 2010-05-17T00:40:19Z Indexed on 2010/05/17 0:50 UTC
Read the original article Hit count: 545

Filed under:
|
|
|

Im having problems when passing an generic List, trough a WCF operation. In this case, there is a List of int. The example 4 is described here in MSDN. Note that in MSDN sample, is described:

// This will serialize and deserialize successfully because the generic List is equivalent to int[], which was added to known types.

Above, is the DataContract:

    [DataContract]
    [KnownType(typeof(int[]))]
    [KnownType(typeof(object[]))]
    public class AccountData
    {
        [DataMember]
        public object accNumber1;

        [DataMember]
        public object accNumber2;

        [DataMember]
        public object accNumber3;

        [DataMember]
        public object accNumber4;


    }

In client side, Im calling the operation like this:

DataTransfer.Service.AccountData data = new DataTransfer.Service.AccountData()
{
  accNumber1 = 100,
  accNumber2 = new int[100],
  accNumber3 = new List<int>(),
  accNumber4 = new ArrayList()
};
cService.AddAccounts(data);

Also, here is the decorations of the generated AccountData obj (WCF proxy):

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="AccountData", Namespace="http://schemas.datacontract.org/2004/07/DataTransfer.Service")]
[System.SerializableAttribute()]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(DataTransfer.Client.CustomerServiceReference.PurchaseOrder))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(DataTransfer.Client.CustomerServiceReference.Customer))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(int[]))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(object[]))]

© Stack Overflow or respective owner

Related posts about .NET

Related posts about serialization