SecRole.RemoveUserRoles Method

The RemoveUserRoles method removes an existing user from an existing role.

[Visual Basic .NET]
Public Sub RemoveUserRoles(
  ByVal Caller As CUserAuth,
  ByVal UserId As String,
  ByVal RoleIds As String()
public void RemoveUserRoles(
  CUserAuth  Caller,
  string  UserId,
  string[]  RoleIds
public: void RemoveUserRoles(
  CUserAuth*  Caller,
  String*  UserId,
  String*  RoleIds __gc[]



Specifies the identity of the caller. The caller must have the prvAssignRole privilege to perform this action. See CUserAuth.


Specifies the ID of the user being removed from the roles. This ID is specified by the platform and is obtained at user creation time or by a bulk retrieve.


Specifies an array of IDs for the roles from which the user is being removed. This is an array of strings, each of which contains one ID.

Return Value

No return value.


If there is an error, SOAP throws an exception and the error message is reported in System.Web.Services.Protocols.SoapException.Detail.OuterXml.

All IDs passed to the platform are GUIDs wrapped in braces. For example: {6522D89A-A752-4455-A2B0-51494C6957C3}


// strServer should be set with the name of the platform Web server
string strServer = "myservername";

// strVirtualDirectory should be set with the name of the Microsoft CRM 
// virtual directory on the platform Web server
string strVirtualDirectory = "mscrmservices";

// Create the URL to the SRF files for platform objects
string strDir = "https://" + strServer + "/" + strVirtualDirectory + "/";

// BizUser proxy object
Microsoft.CRM.Proxy.BizUser user = new Microsoft.CRM.Proxy.BizUser ();
user.Credentials = System.Net.CredentialCache.DefaultCredentials;
user.Url = strDir + "BizUser.srf";

// SecRole proxy object
Microsoft.CRM.Proxy.SecRole secRole = new Microsoft.CRM.Proxy.SecRole ();
secRole.Credentials = System.Net.CredentialCache.DefaultCredentials;
secRole.Url = strDir + "SecRole.srf";

// Declare the caller
Microsoft.CRM.Proxy.CUserAuth userAuth = null;

string strErrorMsg;
   // Get the UserAuth of the current logged-on user
   userAuth = user.WhoAmI();

   string[] roles = new string[2];

   // Retrieve the role ID by name
   string strRoleId = secRole.RetrieveIdFromName(userAuth, userAuth.MerchantId, "Salesperson");
   string strRoleId1 = secRole.RetrieveIdFromName(userAuth, userAuth.MerchantId, "Sales Manager");
   if ((strRoleId != null) && (strRoleId1 != null))
      roles[0] = strRoleId;
      roles[1] = strRoleId1;

      secRole.AssignUserRoles(userAuth, userAuth.UserId, roles);

   // Now remove the roles
   secRole.RemoveUserRoles(userAuth, userAuth.UserId, roles);
catch(System.Web.Services.Protocols.SoapException err)
   // Process the platform error here
   strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml + " Source: " + err.Source );
catch(Exception err)
   // Process other errors here
   strErrorMsg = ("ErrorMessage: " + err.Message + "Source: " + err.Source );


Namespace: Microsoft.CRM.Proxy

Assembly: microsoft.crm.proxy.dll

See Also

© 2003 Microsoft Corporation. All rights reserved.