代码之家  ›  专栏  ›  技术社区  ›  Étienne Brouillard

Azure表存储,ExecuteBatchAsync,操作的意外响应代码:0

  •  1
  • Étienne Brouillard  · 技术社区  · 11 年前

    通过利用Windows Azure SDK,我尝试使用CloudTable.ExecuteBatchAsync和TableBatchOperations插入实体。

    序列化为Json的实体:

    {
        "LastAccessDate":"2015-02-27T00:00:00Z",
        "Title":"Google open-sources HTTP/2-based RPC framework",
        "PublicationDate":"0001-01-01T00:00:00",
        "Id":"tag:theregister.co.uk,2005:story/2015/02/27/google_opensources_http2based_rpc_framework/",
        "LastUpdatedDate":"2015-02-27T00:00:00Z",
        "FeedUrl":"http://www.theregister.co.uk/software/developer/headlines.atom",
        "Url":"http://go.theregister.com/feed/www.theregister.co.uk/2015/02/27/google_opensources_http2based_rpc_framework/",
        "PartitionKey":"http%3a%2f%2fwww.theregister.co.uk%2fsoftware%2fdeveloper%2fheadlines.atom",
        "RowKey":"http%3a%2f%2fgo.theregister.com%2ffeed%2fwww.theregister.co.uk%2f2015%2f02%2f27%2fgoogle_opensources_http2based_rpc_framework%2f",
        "Timestamp":"0001-01-01T00:00:00+00:00",
        "ETag":null
    }
    

    POCO实体代表:

    public class SyndicationFeedArticle : TableEntity
    {        
        public virtual DateTime LastAccessDate { get; set; }
        public virtual string Title { get; set; }
        public virtual DateTime PublicationDate { get; set; }
        public virtual string Id { get; set; }
        public virtual DateTime LastUpdatedDate { get; set; }
        public virtual string FeedUrl { get; set; }
        public virtual string Url { get; set; }
    }
    

    当实体是通过RSS xml处理构造的时,问题就出现了。插入抛出的ExecuteBatch Unexpected response code for operation : 0 。我确实理解这意味着索引0处的批处理操作失败。通常情况下,分区键或行键不正确是一个问题,例如包含无效字符(这不是上面的情况)或大小超过1kb(在这种情况下不适用)。

    让我困惑的是:

    • 单元测试和业务代码实体(虽然构造不同)都生成完全相同的Json序列化数据
    • 两个过程(手动 new() 创建和RSS业务代码)在单元测试中运行良好
    • 在Emulator上存储时完全没有问题,仅在Azure Cloud中失败。

    我正在寻找如何解决此问题的指针。我已经在单元测试中重新创建了各种场景,并确保我的实体不会打破对键的限制,但没有运气。我的主要问题是,为什么我不能在模拟器和云之间获得恒定的行为。这真的会帮助我,或者至少,它会让我找到解决这个问题的另一种方法。

    谢谢

    1 回复  |  直到 11 年前
        1
  •  2
  •   Étienne Brouillard    11 年前

    好吧,弄明白了。 在这种特定情况下会发生什么:

    PublicationDate 使用DateTimeOffset.Date作为源值实例化,该值可以设置为MinValue。表存储不支持DateTime列的MinValue。

    <error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <code>OutOfRangeInput</code> <message xml:lang="en-US">One of the request inputs is out of range. RequestId:9e74bf7a-0002-004e-1142-16dabb000000 Time:2015-02-28T02:01:42.2124803Z</message> </error>

    我更改了 DateTime? 并将其作为业务规则进行管理。当然,我想知道为什么在模拟器上本地支持这一点。。。