BizUser.CreateAndRetrieve Method

The CreateAndRetrieve method creates a user and then retrieves the newly created user.

Syntax

[Visual Basic .NET]
Public Function CreateAndRetrieve(
  ByVal Caller As CUserAuth,
  ByVal User As String
) As String
[C#]
public string CreateAndRetrieve(
  CUserAuth  Caller,
  string  User
);
[C++]
public: String* CreateAndRetrieve(
  CUserAuth*  Caller,
  String*  User
);

Parameters

Caller

Specifies the identity of the caller. The caller must have the prvCreateUser and prvReadUser privileges to perform this action. See CUserAuth.

User

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 XML data containing the newly created user information. The XML schema is described by systemuser.xsd.

Remarks

After the user is created, call the SecRole.AssignUserRoles method to assign proper security roles to the user.

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

[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 = "http://" + strServer + "/" + virtualDirectory + "/";

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

string strErrorMsg;
string strBizID = "{0876468B-8FC4-4381-8D81-C0B4D05E9386}";
try
{
   Microsoft.CRM.Proxy.CUserAuth userAuth = bizUser.WhoAmI();

   string sUserName = "jpeoples";

   // Set up the XML string for the user
   // The domainname field must map to an existing Active Directory user name
   string strUserXml = "<systemuser><domainname>" + sUserName + "</domainname>";
   strUserXml += "<firstname>John</firstname>";
   strUserXml += "<lastname>Peoples</lastname>";
   strUserXml += "<businessunitid>" + strBizID + "</businessunitid>";
   strUserXml += "</systemuser>";

   string strNewUserXml = bizUser.CreateAndRetrieve(userAuth, 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 );
}

Requirements

Namespace: Microsoft.CRM.Proxy

Assembly: microsoft.crm.proxy.dll

See Also

© 2003 Microsoft Corporation. All rights reserved.