BizOrganization.CreateUser Method

The CreateUser method creates a user in the business unit that is specified in the user XML data. The user is assigned the role of System Administrator. To perform this action, the caller must be a domain administrator.

Syntax

[Visual Basic .NET]
Public Function CreateUser(
  ByVal UserXml As String
) As String
[C#]
public string CreateUser(
  string  UserXml
);
[C++]
public: String* CreateUser(
  String*  UserXml
);

Parameters

UserXml

Specifies an XML string containing the user information. The XML schema is described by systemuser.xsd.

Return Value

Returns a String type that specifies the ID of the newly created user.

Remarks

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}

Example

Note The following example contains sample data for the administrator login name and password. This is for illustration only. User credentials should never be hard-coded. For more information, see "Building Secure ASP.NET Applications" at msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetch12.asp.

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

// virtualDirectory should be set with the name of the Microsoft CRM
// virtual directory on the platform Web server
string virtualDirectory = "mscrmservices";
string strDir = "https://" + strServer + "/" + virtualDirectory + "/";
      
// BizOrganization proxy object
Microsoft.Crm.Platform.Proxy.BizOrganization organization = new Microsoft.Crm.Platform.Proxy.BizOrganization ();
organization.Credentials = System.Net.CredentialCache.DefaultCredentials;
organization.Url = strDir + "BizOrganization.srf";

string strUserXML = "";
string strOrgName = "Wingtip Toys";

// Get the GUID of an OU from Active Directory
// that is going to represent the OU for the Microsoft CRM organization object
// The name of the OU should be the same as the name of the Microsoft CRM organization
// The organization is created in Microsoft CRM
string strOrgId = "{3BECB6A6-0DD8-4061-98D9-0B9E897C5027}";

// See Note above regarding the use of hard-coded passwords
string strDomainAdminUserName = "Administrator";
string strDomainAdminUserPass = "Admin";
string strDomainName = "MyDomain";

// A business unit ID where the user is to be created
string strBizId = "{10594FB4-EDE7-4A4A-81E9-E165DEB34756}";
string strUserId = "";
string strErrorMsg = "";


try
{
   strUserXML ="<systemuser>" + 
            "<firstname>Ken</firstname>" +
            "<lastname>Sanchez</lastname>" + 
            "<domainname>DomainName</domainname>" +  
            "<businessunitid>" + strBizId + "</businessunitid>" +
            "</systemuser>";
                     
   // Set the credentials of the organization proxy with
   // the credentials of a user who has domain administrator rights
   organization.Credentials = new System.Net.NetworkCredential(   strDomainAdminUserName, 
      strDomainAdminUserPass, 
      strDomainName);

   // Create another user with the role of System Administrator
   // in the specified business unit
   strUserId = organization.CreateUser(strUserXML);
}
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 );
}
finally
{
   // Set the credentials back to the default
   organization.Credentials = System.Net.CredentialCache.DefaultCredentials;
}

Requirements

Namespace: Microsoft.Crm.Platform.Proxy

Assembly: Microsoft.Crm.Platform.Proxy.dll

See Also

© 2005 Microsoft Corporation. All rights reserved.