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