

感觉WCF给分布式开发带来的方便不是一般的,效率好像也还不错(编译好第1+n次的访问速度总是比第n次快【本机上】),
然后用LinQ写了个简单的DataAccessLayer,先是定义接口,我们叫它做契约!它加了WCF的特性,继承自它的服务会自动继承其特性,数据库用Northwind
1
using
System;
2
using
System.Collections.Generic;
3
using
System.Linq;
4
using
System.Text;
5
using
ExtjsNorthwind.Model;
6
using
System.ServiceModel;
7
using
System.ServiceModel.Web;
8
namespace
ExtjsNorthwind.ServiceContract
9
{
10
[ServiceContract]
11
12
public interface IProductService
13
{
14
[OperationContract]
15
[WebInvoke(BodyStyle=WebMessageBodyStyle.Bare,RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json,UriTemplate="/Get")]
16
List<Product> GetProductById(int id);
17
[OperationContract]
18
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/GetAll")]
19
List<Product> GetProducts();
20
}
21
}
接下来实现这个契约

2

3

4

5

6

7

8

9



10

11

12

13



14

15

16

17

18

19

20

21
















































此外测试了一个简单的一对多的序列化
写了一个Student类代码很简单,就不贴了,其中有一个List<Product>类型得ProductList属性,返回这个学生买的产品资料!加上[DataMember]特性!OK: 代码下载