重用我PagedList对象WCF [英] Reusing my PagedList object on WCF

查看:175
本文介绍了重用我PagedList对象WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我有一个自定义集合 PagedList< T> 正从我的WCF服务返回 PagedListOfEntitySearchResultW_SH0Zpu5 当T是EntitySearchResult对象。

我要重用这个 PagedList< T> 应用和服务之间键入

我的情况:

我创建了一个 PagedList< T> 键入与继承名单< T>
这种类型是上是在应用程序和WCF服务引用的分离组件。

我使用的scvutil的/参考选项启用类型重用。我也不想回来,所以我也使用 /集映射到泛型列表类型的数组。
我用下面的 SvcUtil工具命令生成服务代理:

 C:\\ Program Files文件(x86)的\\微软的SDK \\ WINDOWS \\ v7.0A \\ BIN \\ NETFX 4.0工具\\ 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]
 公共部分类PagedList< T> :列表< T>
 {  公共PagedList(){}  ///<总结>
  ///创建PagedList对象的新实例,并且不应用任何分页算法。
  ///唯一计算的属性是总页数,一切需要必须传递给该对象。
  ///< /总结>
  ///< PARAM NAME =源>< /参数>
  ///< PARAM NAME =PAGENUMBER>< /参数>
  ///< PARAM NAME =pageSize的>< /参数>
  ///< PARAM NAME =总记录>< /参数>
  公共PagedList(IEnumerable的< T>源,诠释PAGENUMBER,诠释的pageSize,INT总记录)
  {
   如果(来源== NULL)
    来源=新的List< T>();   this.AddRange(源);   PagingInfo.PageNumber = PAGENUMBER;
   每页= pageSize的;
   总记录=总记录;
  }  公共PagedList(IEnumerable的< T>源,PagingInfo分页)
  {
   this.AddRange(源);
   this._pagingInfo =分页;
  }  [数据成员]
  公众诠释总记录{搞定;组; }  [数据成员]
  公众诠释每页{搞定;组; }  公众诠释总页数()
  {
   如果(this.TotalRecords大于0&放大器;&放大器;每页大于0)
    回报(INT)Math.Ceiling((双)总记录/(双)每页);
   其他
    返回0;
  }  公共BOOL?有previousPage()
  {
   返回(PagingInfo.PageNumber→1);
  }  公共BOOL? HasNextPage(){回报(PagingInfo.PageNumber<总页数()); }  公共BOOL? IsFirstPage(){返回PagingInfo.PageNumber == 1; }  公共BOOL? IsLastPage(){返回PagingInfo.PageNumber ==总页数(); }  PagingInfo _pagingInfo = NULL;
  [数据成员]
  公共PagingInfo PagingInfo
  {
   获得{
    如果(_pagingInfo == NULL)
     _pagingInfo =新PagingInfo();    返回_pagingInfo;
   }
   组
   {
    _pagingInfo =价值;
   }
  }
 }


解决方案

我想我知道这里发生了什么......结果
/集 /参考在这种情况下,矛盾的是我PagedList对象从继承清单< T>
我只是改变了/集合下,现在的作品。

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

的事情是,我的所有集合将检索为PagedList。结果
这是不是一个真正的问题,但对我来说将需要能够检索列表< T> 默认和 PagedList< T> 在需要的时候。

The problem:

I have a custom collection PagedList<T> that is being returned from my WCF service as PagedListOfEntitySearchResultW_SH0Zpu5 when T is EntitySearchResult object.

I want to reuse this PagedList<T> type between the application and the service.

My scenario:

I've created a PagedList<T> type that inherits from List<T>. This type is on a separated assembly that is referenced on both application and WCF service.

I'm using the /reference option on the scvutil to enable the type reusing. I also don't want any arrays returned so I also use the /collection to map to the generic List type. I'm using the following svcutil command to generate the service proxy:

"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

The PagedList object is something like:

 [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;
   }
  }
 }

解决方案

I think I know what's happening here...
The /collection is conflicting with the /reference on this case as my PagedList object inherits from List<T>. I just changed the /collection to the following and it now works.

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

The thing is that all my collections will the retrieved as PagedList.
This isn't really a problem for me but would be need to be able to retrieve List<T> by default and PagedList<T> when needed.

这篇关于重用我PagedList对象WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆