在WCF上重用我的PagedList对象

问题:

当T是EntitySearchResult对象时,我有一个自定义集合PagedList ,它作为PagedListOfEntitySearchResultW_SH0Zpu5从我的WCF服务返回。

我想在应用程序和服务之间重用此PagedList类型。

我的情景:

我创建了一个inheritance自ListPagedList类型。 此类型位于应用程序和WCF服务上引用的独立程序集上。

我在scvutil上使用/ reference选项来启用类型重用。 我也不希望返回任何数组,所以我也使用/collection映射到通用List类型。 我正在使用以下svcutil命令来生成服务代理:

 "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\svcutil.exe" /collectionType:System.Collections.Generic.List`1 /reference:..\..\bin\Debug\App.Utilities.dll http://localhost/App.MyService/MyService.svc?wsdl /namespace:*,"App.ServiceReferences.MyService" /out:..\ServiceProxy\MyService.cs 

PagedList对象类似于:

  [CollectionDataContract] public partial class PagedList : List { public PagedList() { } ///  /// Creates a new instance of the PagedList object and doesn't apply any pagination algorithm. /// The only calculated property is the TotalPages, everything else needed must be passed to the object. ///  ///  ///  ///  ///  public PagedList(IEnumerable source, int pageNumber, int pageSize, int totalRecords) { if (source == null) source = new List(); this.AddRange(source); PagingInfo.PageNumber = pageNumber; PageSize = pageSize; TotalRecords = totalRecords; } public PagedList(IEnumerable source, PagingInfo paging) { this.AddRange(source); this._pagingInfo = paging; } [DataMember] public int TotalRecords { get; set; } [DataMember] public int PageSize { get; set; } public int TotalPages() { if (this.TotalRecords > 0 && PageSize > 0) return (int)Math.Ceiling((double)TotalRecords / (double)PageSize); else return 0; } public bool? HasPreviousPage() { return (PagingInfo.PageNumber > 1); } public bool? HasNextPage() { return (PagingInfo.PageNumber < TotalPages()); } public bool? IsFirstPage() { return PagingInfo.PageNumber == 1; } public bool? IsLastPage() { return PagingInfo.PageNumber == TotalPages(); } PagingInfo _pagingInfo = null; [DataMember] public PagingInfo PagingInfo { get { if (_pagingInfo == null) _pagingInfo = new PagingInfo(); return _pagingInfo; } set { _pagingInfo = value; } } } 

我想我知道这里发生了什么……
由于我的PagedList对象inheritance自List因此/collection与此案例的/reference冲突。 我刚刚将/ collection更改为以下内容,现在可以正常工作了。

 /collectionType:App.Utilities.Data.PagedList`1 

问题是我的所有集合都将被检索为PagedList。
这对我来说不是一个真正的问题,但是需要能够在需要时检索ListPagedList