allendehl
allendehl

Reputation: 129

WCF Deserializes List<object> as object[]

I'm having a bit of a situation here. I need to pass into a WCF service an object that has a property that is a List of another object. Both object are defined within the WCF service. I'm having two problems here:

1- The custom constructors for any of the two objects are not available in the client

2- The List<> are available to me in the client as array, not letting me add anything to it to later pass t back to the server

Any help will be greatly appreciated

WCF Code:

[Serializable]
[DataContract]
public class PCParamResultEntity
{
    #region Properties
    [DataMember]
    public string SpecName { get; set; }
    [DataMember]
    public string SpecValue { get; set; }
    [DataMember]
    public string Grade { get; set; }
    #endregion

    #region Constructors        
    public PCParamResultEntity(string specName, string specValue, string grade)
    {
        SpecName = specName;
        SpecValue = specValue;
        Grade = grade;
    }
    #endregion
}
[Serializable]
[DataContract]
public class PCCheckResultEntity
{
    #region Properties
    [DataMember]
    public string GlobalResult { get; set; }
    [DataMember]
    public List<PCParamResultEntity> Results { get; set; }        
    #endregion

    #region Constructors        
    public PCCheckResultEntity(string globalResult, List<PCParamResultEntity> results)
    {
        GlobalResult = globalResult;
        Results = results;
    }
    #endregion


}

Client Code:

        PCCheckResultEntity result = new PCCheckResultEntity();
        result.GlobalResult = pcCheckresult.GlobalResult;

        foreach (PCParamResult param in pcCheckresult.Results)
        {
            string paramGrade = param.Grade;
            PCParamResultEntity resultEntity = new PCParamResultEntity();
            resultEntity.SpecName = param.SpecName;
            resultEntity.SpecValue = param.SpecValue;
            resultEntity.Grade = paramGrade;
            result.Results.????
        }
        return result;

Upvotes: 0

Views: 273

Answers (1)

Petar Vučetin
Petar Vučetin

Reputation: 3615

Collection (and List) is very much specific to .Net, WCF does not expose it to the metadata of the service. WCF provides dedicated marshaling rules for collection. Collection will be exposed as array in service metadata.

If you are using AddServiceReference click Advanced and select "Collection type" and specify Generic.List.

Upvotes: 1

Related Questions