• 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>。问题所有解决。


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

    经过上述两事件总结能够得出,对于不论什么在序列化过程中可能出错的情况。都会导致server返回0字节数据而报此错误。








  • 相关阅读:
    BZOJ.3720.Gty的妹子树(树分块)
    洛谷.3369.[模板]普通平衡树(Splay)
    洛谷.3224.[HNOI2012]永无乡(Splay启发式合并)
    洛谷.2234.[HNOI2002]营业额统计(Splay)
    洛谷.1486.[NOI2004]郁闷的出纳员(Splay)
    BZOJ.1901.Dynamic Rankings(线段树套平衡树 Splay)
    洛谷.1110.[ZJOI2007]报表统计(Splay Heap)
    洛谷.2596.[ZJOI2006]书架(Splay)
    BZOJ.1597.[Usaco2008 Mar]土地购买(DP 斜率优化)
    洛谷.2042.[NOI2005]维护数列(Splay)
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/6943201.html
Copyright © 2020-2023  润新知