转载:http://blog.csdn.net/fangxing80/article/details/26940845
原始的 WebService 如下:
[csharp] view plaincopy
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Services;
- using WebService1.Entity;
- using WebService1.Service;
- using System.Web.Services.Protocols;
- namespace WebService1
- {
- [WebService(Namespace = "http://tempuri.org/")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.ComponentModel.ToolboxItem(false)]
- public class Service1 : System.Web.Services.WebService
- {
- [WebMethod]
- public PageResult<Order> QueryOrder(Query<OrderCondition> queryInfo)
- {
- OrderService service = new OrderService();
- return service.Query(queryInfo);
- }
- }
- }
PageResult<T>, Query<T> 将统一的业务部分抽取出来,这样定义其他的业务对象就能简化了。
[html] view plaincopy
- using System;
- using System.Collections.Generic;
- namespace WebService1.Entity
- {
- [Serializable]
- public class PageResult<T>
- {
- public int PageNo { get; set; }
- public int PageSize { get; set; }
- public int TotalCount { get; set; }
- public int PageCount { get; set; }
- public bool HasNextPage { get; set; }
- public List<T> Data { get; set; }
- }
- }
[csharp] view plaincopy
- using System;
- using System.Collections.Generic;
- namespace WebService1.Entity
- {
- [Serializable]
- public class Query<T>
- {
- public int PageNo { get; set; }
- public int PageSize { get; set; }
- public T Condition { get; set; }
- }
- }
时间: 2024-10-11 13:03:34