Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF通用结果类始终为空_C#_Wcf_Generics - Fatal编程技术网

C# WCF通用结果类始终为空

C# WCF通用结果类始终为空,c#,wcf,generics,C#,Wcf,Generics,我的服务器响应有以下通用类: [DataContract] public class GenericResult<T> { public List<T> ListResult { get; set; } public T Result { get; set; } public string Message { get; set; } } [DataContract] 公共类GenericResul

我的服务器响应有以下通用类:

[DataContract]
    public class GenericResult<T>
    {
        public List<T> ListResult { get; set; }
        public T Result { get; set; }
        public string Message { get; set; }

    }
[DataContract]
公共类GenericResult
{
公共列表ListResult{get;set;}
公共T结果{get;set;}
公共字符串消息{get;set;}
}
此GetAllBrandsTest方法用于将数据返回到客户端:

public async Task<GenericResult<Brand>> GetAllBrandsTest()
        {
            var result = await repo.GetAllAsync<Brand>();
            return new GenericResult<Brand>()
            {
                ListResult = result.ToList(),
                Message = "Success"
            };
        }
public异步任务GetAllBrandsTest()
{
var result=await repo.GetAllAsync();
返回新的GenericResult()
{
ListResult=result.ToList(),
Message=“成功”
};
}
使用此方法一切正常GetAllBrands:

public async Task<IList<Brand>> GetAllBrands()
        {            
            return await repo.GetAllAsync<Brand>();
        }
公共异步任务GetAllBrands() { return wait repo.GetAllAsync(); } 但是当我调用GetAllBrandsTest时,结果是空的

[DataContract]
[KnownType(typeof(Brand))]
public class GenericResult<T>
{
    [DataMember]
    public List<Brand> ListResult { get; set; }
    [DataMember]
    public Brand Result { get; set; }
    [DataMember]
    public string Message { get; set; }
}



我们要么用
DataContract
属性和
DataMember
属性装饰类,要么删除
DataContract
属性和
DataMember
属性。因为当复杂数据类型为而不指定任何XML序列化程序时,默认情况下将使用
DataContract
序列化程序

非常感谢,我忘了用DataMember装饰它了。
[DataContract]
[KnownType(typeof(CircleType))]
[KnownType(typeof(TriangleType))]
public class CompanyLogo2

    [DataMember]
    private Shape ShapeOfLogo;
    [DataMember]
    private int ColorOfLogo;
}
[DataContract]
public class Shape { }

[DataContract(Name = "Circle")]
public class CircleType : Shape { }

[DataContract(Name = "Triangle")]
public class TriangleType : Shape { }