C# 在WCF上重用我的PagedList对象
问题是: 我有一个自定义集合C# 在WCF上重用我的PagedList对象,c#,asp.net,wcf,C#,Asp.net,Wcf,问题是: 我有一个自定义集合PagedList,当T是EntitySearchResult对象时,它将从我的WCF服务返回为PagedListOfEntitySearchResultW_SH0Zpu5 我想在应用程序和服务之间重用此PagedList类型 我的设想: 我创建了一个从列表继承的页面列表类型。 此类型位于应用程序和WCF服务上都引用的独立程序集上 我在scvutil上使用/reference选项来启用类型重用。我也不希望返回任何数组,因此我还使用/collection映射到泛型列表类
PagedList
,当T是EntitySearchResult对象时,它将从我的WCF服务返回为PagedListOfEntitySearchResultW_SH0Zpu5
我想在应用程序和服务之间重用此PagedList
类型
我的设想:
我创建了一个从列表继承的页面列表
类型。
此类型位于应用程序和WCF服务上都引用的独立程序集上
我在scvutil上使用/reference选项来启用类型重用。我也不希望返回任何数组,因此我还使用/collection
映射到泛型列表类型。
我正在使用以下svcuti
命令生成服务代理:
"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<T> : List<T>
{
public PagedList() { }
/// <summary>
/// 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.
/// </summary>
/// <param name="source"></param>
/// <param name="pageNumber"></param>
/// <param name="pageSize"></param>
/// <param name="totalRecords"></param>
public PagedList(IEnumerable<T> source, int pageNumber, int pageSize, int totalRecords)
{
if (source == null)
source = new List<T>();
this.AddRange(source);
PagingInfo.PageNumber = pageNumber;
PageSize = pageSize;
TotalRecords = totalRecords;
}
public PagedList(IEnumerable<T> 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;
}
}
}
[CollectionDataContract]
公共部分类页面列表:列表
{
公共页面列表(){}
///
///创建PagedList对象的新实例,不应用任何分页算法。
///唯一的计算属性是TotalPages,其他需要的所有内容都必须传递给对象。
///
///
///
///
///
公共页面列表(IEnumerable源、int pageNumber、int pageSize、int totalRecords)
{
if(source==null)
source=新列表();
此.AddRange(源);
PaginInfo.PageNumber=页码;
PageSize=页面大小;
TotalRecords=TotalRecords;
}
公共分页列表(IEnumerable源,分页信息分页)
{
此.AddRange(源);
这。_paginfo=分页;
}
[数据成员]
公共整数TotalRecords{get;set;}
[数据成员]
公共int PageSize{get;set;}
公共整数页()
{
if(this.TotalRecords>0&&PageSize>0)
返回(整数)数学上限((双)TotalRecords/(双)PageSize);
其他的
返回0;
}
公共图书馆?上一页()
{
返回(PaginInfo.PageNumber>1);
}
public bool?HasNextPage(){return(pagininfo.PageNumber
我想我知道这里发生了什么…
在这种情况下,/collection
与/reference
冲突,因为我的PagedList对象继承自列表
。
我刚刚将/collection更改为以下内容,现在可以使用了
/collectionType:App.Utilities.Data.PagedList`1
问题是,我的所有收藏都将作为PagedList检索。
这对我来说不是什么问题,但需要能够在默认情况下检索列表
,并在需要时检索页面列表
。所以问题真的是?!?!?。。。。。如何使WCF服务返回一个列表作为默认集合类型,并在需要时返回从列表继承的页面列表?