设置MaxResultsPerCollection会生成无效的XML

时间:2012-10-31 11:48:57

标签: wcf-data-services odata

如果我将DataServiceConfiguration.MaxResultsPerCollection设置为2,那么当结果更大时,会有<m:error>标记,但生成的XML文件无效(缺少结束<feed>)。为什么?这是预期的吗?如何解析它(正确)?

示例:

public class WcfDataService1 : DataService<DummyContext>
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;

        config.MaxResultsPerCollection = 2;
    }
}

public class DummyContext
{
    public IQueryable<DummyClass> Data
    {
        get
        {
            return Enumerable.Range(1, 10).Select(x => new DummyClass() { Id = x, FooBar = x * 2 }).AsQueryable();
        }
    }
}

[DataServiceKey("Id")]
public class DummyClass
{
    public int Id { get; set; }
    public int FooBar { get; set; }
}

结果:

<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="http://localhost:49627/WcfDataService1.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <id>http://localhost:49627/WcfDataService1.svc/Data</id>
    <title type="text">Data</title>
    <updated>2012-10-31T11:43:03Z</updated>
    <link rel="self" title="Data" href="Data" />
    <entry>
        <id>http://localhost:49627/WcfDataService1.svc/Data(1)</id>
        <category term="WebApplication1.DummyClass" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
        <link rel="edit" title="DummyClass" href="Data(1)" />
        <title />
        <updated>2012-10-31T11:43:03Z</updated>
        <author>
            <name />
        </author>
        <content type="application/xml">
            <m:properties>
                <d:Id m:type="Edm.Int32">1</d:Id>
                <d:FooBar m:type="Edm.Int32">2</d:FooBar>
            </m:properties>
        </content>
    </entry>
    <entry>
        <id>http://localhost:49627/WcfDataService1.svc/Data(2)</id>
        <category term="WebApplication1.DummyClass" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
        <link rel="edit" title="DummyClass" href="Data(2)" />
        <title />
        <updated>2012-10-31T11:43:03Z</updated>
        <author>
            <name />
        </author>
        <content type="application/xml">
            <m:properties>
                <d:Id m:type="Edm.Int32">2</d:Id>
                <d:FooBar m:type="Edm.Int32">4</d:FooBar>
            </m:properties>
        </content>
    </entry>
    <m:error>
        <m:code />
        <m:message xml:lang="cs-CZ">The response exceeds the maximum 2 results per collection.</m:message>
    </m:error>

0 个答案:

没有答案