tags:

views:

61

answers:

2

I have 4 classes: BaseStreamParameter

[DataContract]
[KnownType(typeof(StreamParameter))]
[KnownType(typeof(RepeatableStreamParameter))]
public class BaseStreamParameter
{
    private bool pIsRepeatable;
    [DataMember]
    public bool IsRepeatable
    {
        get { return pIsRepeatable; }
        set { pIsRepeatable = value; }
    }
    private bool pIsFBlock;
    [DataMember]
    public bool IsFBlock
    {
        get { return pIsFBlock; }
        set { pIsFBlock = value; }
    }

    private string pParamName;
    [DataMember]
    public string ParamName
    {
        get { return pParamName; }
        set { pParamName = value; }
    }


    public BaseStreamParameter(bool aIsRepeatable, bool aIsFBlock, string aParamName)
    {
        pIsFBlock = aIsFBlock;
        pIsRepeatable = aIsRepeatable;
        pParamName = aParamName;
    }

    public BaseStreamParameter(string aParamName)
    {
        pIsFBlock = false;
        pIsRepeatable = false;
        pParamName = aParamName;
    }

RepeatableStreamParameter

[DataContract]
public class RepeatableStreamParameter : BaseStreamParameter
{
    private List<BaseStreamParameter> pRepeatableParameters;
    [DataMember]
    public List<BaseStreamParameter> RepeatableParameters
    {
        get { return pRepeatableParameters; }
        set { pRepeatableParameters = value; }
    }

    public RepeatableStreamParameter(bool aIsFBlock, string aParamName)
        : base(true, aIsFBlock, aParamName)
    {
        pRepeatableParameters = new List<BaseStreamParameter>();
    }
}

StreamParameter

[DataContract]
public class StreamParameter : BaseStreamParameter
{
    private string pParamType;
    [DataMember]
    public string ParamType
    {
        get { return pParamType; }
        set { pParamType = value; }
    }

    private string pParamValue;
    [DataMember]
    public string ParamValue
    {
        get { return pParamValue; }
        set { pParamValue = value; }
    }
    private bool pIsEnum;
    [DataMember]
    public bool IsEnum
    {
        get { return pIsEnum; }
        set { pIsEnum = value; }
    }
    private List<string> pEnumList;
    [DataMember]
    public List<string> EnumList
    {
        get { return pEnumList; }
        set { pEnumList = value; }
    }

    public StreamParameter(bool aIsFBlock, string aParamName, string aParamType, string aParamValue, bool aIsEnum, List<string> aEnumList)
        : base(false, aIsFBlock, aParamName)
    {
        pParamType = aParamType;
        pParamValue = aParamValue;
        pIsEnum = aIsEnum;
        pEnumList = aEnumList;
    }

    public StreamParameter(bool aIsFBlock, string aParamName, string aParamType, string aParamValue)
        : base(false, aIsFBlock, aParamName)
    {
        pParamType = aParamType;
        pParamValue = aParamValue;
        pIsEnum = false;
        pEnumList = null;
    }
}

StreamParameterContainer

 [DataContract]
[KnownType(typeof(StreamParameterContainer))]
public class StreamParameterContainer : BaseStreamParameter
{
    private List<BaseStreamParameter> pStreamParameters;
    public StreamParameterContainer(string aParamName)
        : base(aParamName)
    {
        pStreamParameters = new List<BaseStreamParameter>();
    }
    [DataMember]
    public List<BaseStreamParameter> StreamParameters
    {
        get { return pStreamParameters; }
        set { pStreamParameters = value; }
    }

    public int GetCountOfNonRepeatingParameters()
    {
        int count = 0;
        foreach (BaseStreamParameter bsp in pStreamParameters)
        {
            if (bsp is StreamParameter)
                count++;
        }
        return count;
    }
}

So I have a StreamParameterContainer object whose StreamParameters property contains a RepeatableStreamParameter whose RepeatableParameters property contains 7 StreamParameter objects. This is all true when I make the call to the WCF web service. On the other end the RepeatableStreamParameter's RepeatableParameters property is empty.

Can any one tell me why?
is there someway to see what is being sent after I make the call in the client, but before it gets to the server?

+1  A: 

I tested out your code with:

DataContractSerializer serializer = new DataContractSerializer(typeof(BaseStreamParameter));

MemoryStream stream = new MemoryStream();
var parameter = new BaseStreamParameter.RepeatableStreamParameter(true, "test");
parameter.RepeatableParameters.Add(new BaseStreamParameter("test2"));
serializer.WriteObject(stream, parameter);

stream.Position = 0;
var read = (BaseStreamParameter.RepeatableStreamParameter)serializer.ReadObject(stream);
Console.WriteLine(read.RepeatableParameters[0].ParamName);

This printed out "test2", as expected.

I acknowledge this is not an answer to your question, but I'm curious if/why you don't see the same results.

Kirk Woll
Me too. When I run your code in a separate project I get the same result. is it possible that a different serializer is being used? I don't think I explicitly set one anywhere.
scott
A: 

The dll on the server was out of date. When I updated that everything worked fine.

scott