WCF问题集锦:ReadResponse failed: The server did not return a complete response for this request.

今日,对代码进行单元测试时,发现方法GetAllSupplyTypes报如下错误:

[Fiddler] ReadResponse() failed: The server did not return a complete response for this request. Server returned 0 bytes.

经过对比,唯一的差异是该方法返回的数据对象是一个继承于另一个集合对象的对象,代码如下:

/// <summary>
/// SupplyType的值的集合
/// </summary>
[DataContract]
public class SupplyTypeResults : List<SupplyType>
{
    /// <summary>
    /// 构造函数
    /// </summary>
    public SupplyTypeResults()
    {
        this.Add(new SupplyType
        {
            SupplyTypeId = 2,
            SupplyTypeName = "其他投放方式"
        });

        this.Add(new SupplyType
        {
            SupplyTypeId = 1,
            SupplyTypeName = "平台自动投放"
        });

        this.Add(new SupplyType
        {
            SupplyTypeId = 0,
            SupplyTypeName = "客户主动领取"
        });
    }
}

其中,SupplyType定义如下:

/// <summary>
/// 优惠券发行方式
/// </summary>
[DataContract]
public class SupplyType
{
    /// <summary>
    /// 发行方式Id
    /// </summary>
    [DataMember(Name = "supplyTypeId")]
    public int SupplyTypeId { get; set; }

    /// <summary>
    /// 发行方式名称
    /// </summary>
    [DataMember(Name = "supplyTypeName")]
    public string SupplyTypeName { get; set; }
}
自以为继承与一个WCF能正常序列化的对象,而且在SupplyTypeResults上也加了DataContract应该没有问题,但是就是报错。

后来不再使用SupplyTypeResults类,在代码中直接使用List<SupplyType>,问题全部解决。


之后,有发现另一个方法也会产生该问题,但是,该方法不属于此原因范畴,经过一阵排查,发现返回类中有个日期属性没有赋值,导致了该错误的抛出。

经过上述两事件总结可以得出,对于任何在序列化过程中可能出错的情况,都会导致服务器返回0字节数据而报此错误。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值