不废话了。翠花,上代码:
ServiceContracts:
IMembershipService.cs:
ServiceImplementation:
MembershipService.cs:
ServiceContracts:
IMembershipService.cs:
1
using System;
2
using System.Web.Security;
3
using System.ServiceModel;
4
5
namespace Infrastructure.ServiceContracts
6
{
7
[ServiceContract(Namespace = http://Infrastructure.ServiceContracts/, Name = "IMembershipService", SessionMode = SessionMode.Allowed)]
8
public interface IMembershipService
9
{
10
[OperationContract]
11
MembershipUser CreateUser(string username, string password);
12
13
[OperationContract(Name = "CreateUserWithEmail")]
14
MembershipUser CreateUser(string username, string password, string email);
15
16
[OperationContract(Name = "CreateUserWithQuestion")]
17
MembershipUser CreateUser(string username, string password, string email,
18
string passwordQuestion,
19
string passwordAnswer,
20
bool isApproved,
21
out MembershipCreateStatus status
22
);
23
24
[OperationContract(Name = "CreateUserWithProviderUserKey")]
25
MembershipUser CreateUser(string username, string password, string email,
26
string passwordQuestion,
27
string passwordAnswer,
28
bool isApproved,
29
Object providerUserKey,
30
out MembershipCreateStatus status
31
);
32
33
[OperationContract(Name = "DeleteUserDefault")]
34
bool DeleteUser(string username);
35
36
[OperationContract]
37
bool DeleteUser(string username, bool deleteAllRelatedData);
38
39
[OperationContract]
40
MembershipUserCollection GetAllUsers();
41
42
[OperationContract(Name = "GetAllUsersByPaging")]
43
MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords);
44
45
[OperationContract]
46
MembershipUser GetUser();
47
48
[OperationContract(Name = "GetUserIsOnline")]
49
MembershipUser GetUser(bool userIsOnline);
50
51
[OperationContract(Name = "GetUserByProviderUserKey")]
52
MembershipUser GetUser(Object providerUserKey);
53
54
[OperationContract(Name = "GetUserByUsername")]
55
MembershipUser GetUser(string username);
56
57
[OperationContract(Name = "GetUserByKeyAndIsOnline")]
58
MembershipUser GetUser(Object providerUserKey, bool userIsOnline);
59
60
[OperationContract(Name = "GetUserByNameAndIsOnline")]
61
MembershipUser GetUser(string username, bool userIsOnline);
62
63
[OperationContract]
64
string GetUserNameByEmail(string emailToMatch);
65
66
[OperationContract]
67
void UpdateUser(MembershipUser user);
68
69
[OperationContract]
70
bool ValidateUser(string username, string password);
71
}
72
}
73

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

ServiceImplementation:
MembershipService.cs:
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.ServiceModel;
5
using System.Web.Security;
6
using Infrastructure.ServiceContracts;
7
8
namespace CoralMIS.Infrastructure.ServiceImplementation
9
{
10
[ServiceBehavior(Name = "MembershipService",
11
Namespace = http://Infrastructure.ServiceImplementation/2007/06)]
12
public class MembershipService : IMembershipService
13
{
14
IMembershipService 成员
125
}
126
}

2

3

4

5

6

7

8

9

10

11

12

13

14

125

126

至于Role的实现,请参考上面。app.config,web.config中的<System.Web>原来怎么配置现在还怎么配置,我在这里只是简单地给出了一个思路,也可以很方便的改为Web Service,Remoting服务包装。欢迎大家拍砖:)
BTW:《Programming.WCF.Services》这本书里的Credentials Manager utility也有上Membership和Role的包装,可是在我看来过于复杂了:),所以自己做了上面的工作。PWS这本书的随书代码(WCF的一些扩展,一些工具,帮助类)写得很不错,我手上有,不知道是否应该放出来跟大家Sharing,请各位指点,谢谢。