1

如果我设置DataServiceConfiguration.MaxResultsPerCollection为 ie,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>
4

0 回答 0