积极答复者
(急)代码撤销分享怎么做的?

问题
-
各位大大,现在我急需做一个功能:批量撤销分享对象!不过找了半天也没找到解决办法,各位,帮帮忙!
我找了SDK,说撤销共享是用RevokeAccess!
SDK的例子:
[C#] // Set up the CRM service. CrmAuthenticationToken token = new CrmAuthenticationToken(); // You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication. token.AuthenticationType = 0; token.OrganizationName = "AdventureWorksCycle"; CrmService service = new CrmService(); service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx"; service.CrmAuthenticationTokenValue = token; service.Credentials = System.Net.CredentialCache.DefaultCredentials; // Create the SecurityPrincipal. SecurityPrincipal principal = new SecurityPrincipal(); principal.Type = SecurityPrincipalType.User; // PrincipalId is the GUID of the user whose access is being revoked. principal.PrincipalId = new Guid("7B222F98-F48A-4AED-9D09-77A19CB6EE82"); // Create the target for the request. TargetOwnedAccount target = new TargetOwnedAccount(); // EntityId is the GUID of the account to which access is being revoked. target.EntityId = new Guid("2B951FBC-1C56-4430-B23B-20A1349068F3"); // Create the request object. RevokeAccessRequest revoke = new RevokeAccessRequest(); // Set the properties of the request object. revoke.Revokee = principal; revoke.Target = target; // Execute the request. RevokeAccessResponse revoked = (RevokeAccessResponse)service.Execute(revoke);
我照上面的编写代码,测试撤销共享某客户,但是还是没用!
我的代码:
MyService.account account = (MyService.account)item; MyService.SecurityPrincipal principal = new MyService.SecurityPrincipal(); principal.Type = MyService.SecurityPrincipalType.User; principal.PrincipalId = account.ownerid.Value;//只保留负责人可以看 MyService.TargetOwnedAccount target = new MyService.TargetOwnedAccount(); target.EntityId = account.accountid.Value; try { MyService.RevokeAccessRequest revoke = new MyService.RevokeAccessRequest(); revoke.Revokee = principal; revoke.Target = target; MyService.RevokeAccessResponse revoked = (MyService.RevokeAccessResponse)server.Execute(revoke); } catch { throw; }
我不知是不是我写错了,或者理解错了,各位,帮忙看看,谢谢了!
答案
-
你需要查询出所有共享该记录的用户,然后做下循环 移除共享
TargetOwnedAccount targetAccount = new TargetOwnedAccount();
targetAccount.EntityId = account.accountid.Value;RetrieveSharedPrincipalsAndAccessRequest retrieve = new RetrieveSharedPrincipalsAndAccessRequest();
retrieve.Target = targetAccount;RetrieveSharedPrincipalsAndAccessResponse retrieved = (RetrieveSharedPrincipalsAndAccessResponse)service.Execute(retrieve);
foreach (PrincipalAccess pa in retrieved.PrincipalAccesses)
{SecurityPrincipal principal = new SecurityPrincipal();
principal.Type = SecurityPrincipalType.User;principal.PrincipalId = pa.Principal.PrincipalId;
TargetOwnedAccount targetRevoke = new TargetOwnedAccount();
targetRevoke.EntityId = account.accountid.Value;RevokeAccessRequest revoke = new RevokeAccessRequest();
revoke.Revokee = principal;
revoke.Target = targetRevoke;RevokeAccessResponse revoked = (RevokeAccessResponse)service.Execute(revoke);
}
刀客 | MSN:caims@techsun.com | BLOG:http://caims.cnblogs.com | 提供微软CRM高级开发顾问外包- 已标记为答案 荣 2011年2月15日 2:21
全部回复
-
你需要查询出所有共享该记录的用户,然后做下循环 移除共享
TargetOwnedAccount targetAccount = new TargetOwnedAccount();
targetAccount.EntityId = account.accountid.Value;RetrieveSharedPrincipalsAndAccessRequest retrieve = new RetrieveSharedPrincipalsAndAccessRequest();
retrieve.Target = targetAccount;RetrieveSharedPrincipalsAndAccessResponse retrieved = (RetrieveSharedPrincipalsAndAccessResponse)service.Execute(retrieve);
foreach (PrincipalAccess pa in retrieved.PrincipalAccesses)
{SecurityPrincipal principal = new SecurityPrincipal();
principal.Type = SecurityPrincipalType.User;principal.PrincipalId = pa.Principal.PrincipalId;
TargetOwnedAccount targetRevoke = new TargetOwnedAccount();
targetRevoke.EntityId = account.accountid.Value;RevokeAccessRequest revoke = new RevokeAccessRequest();
revoke.Revokee = principal;
revoke.Target = targetRevoke;RevokeAccessResponse revoked = (RevokeAccessResponse)service.Execute(revoke);
}
刀客 | MSN:caims@techsun.com | BLOG:http://caims.cnblogs.com | 提供微软CRM高级开发顾问外包- 已标记为答案 荣 2011年2月15日 2:21