博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

把Membership,Role包装为WCF服务

Posted on 2007-06-28 18:28  江南白衣  阅读(63653)  评论(11编辑  收藏  举报
  不废话了。翠花,上代码:

ServiceContracts:
  IMembershipService.cs:
  
 1using System;
 2using System.Web.Security;
 3using System.ServiceModel;
 4
 5namespace 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

ServiceImplementation:
  MembershipService.cs:
    
  1using System;
  2using System.Collections.Generic;
  3using System.Text;
  4using System.ServiceModel;
  5using System.Web.Security;
  6using Infrastructure.ServiceContracts;
  7
  8namespace 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}


  至于Role的实现,请参考上面。app.config,web.config中的<System.Web>原来怎么配置现在还怎么配置,我在这里只是简单地给出了一个思路,也可以很方便的改为Web Service,Remoting服务包装。欢迎大家拍砖:)

BTW:《Programming.WCF.Services》这本书里的Credentials Manager utility也有上Membership和Role的包装,可是在我看来过于复杂了:),所以自己做了上面的工作。PWS这本书的随书代码(WCF的一些扩展,一些工具,帮助类)写得很不错,我手上有,不知道是否应该放出来跟大家Sharing,请各位指点,谢谢。