Share via


How to Create a Profile Instance Using XML

There are many ways to create a profile in Commerce Server Core Systems. One way is to create a profile based on an XML representation of the user profile. Creating a profile instance from an XML document is a simple process. You construct the XML representation of a profile and pass it to the CreateProfile method of a ProfileManagementContext instance.

To create a profile instance by using XML

  1. Create a subroutine called CreateXMLProfile.

  2. Declare a string to store the XML representation of the profile.

  3. Declare a GUID to store and generate the profile key.

  4. Create an XML representation of the profile.

  5. Create a ProfileManagementContext object.

  6. Load the XML string into an XML document.

  7. Create the profile by calling the CreateProfile method of the ProfileManagementContext instance.

Example

The following code example creates a subroutine called CreateXMLProfile, which creates a profile by using an XML representation of the profile.

private void CreateXMLProfile()
{
    // Declare variables.
    String xmlData = "";
    String myGUID = Guid.NewGuid().ToString();
    XmlDocument profileXMLDoc = new XmlDocument();

    // Create XML representation of the user profile.
    xmlData += @"<ProfileDocument>";
    xmlData += @"   <UserObject>";
    xmlData += @"<GeneralInfo>";
    xmlData += @"<user_id>" + myGUID + "</user_id>";
    xmlData += @"           <user_security_password>myPassword</user_security_password>";
    xmlData += @"           <password_question>myQuestion</password_question>";
    xmlData += @"           <password_answer>myAnswer</password_answer>";
    xmlData += @"<email_address>someone@microsoft.com</email_address>";
    xmlData += @"<direct_mail_opt_out>0</direct_mail_opt_out>";
    xmlData += @"<express_checkout>0</express_checkout>";
    xmlData += @"</GeneralInfo>";
    xmlData += @"       <AccountInfo>";
    xmlData += @"           <account_status>1</account_status>";
    xmlData += @"       </AccountInfo>";
    xmlData += @"</UserObject>";
    xmlData += @"</ProfileDocument>";

    // Access Profiles Web service.
    ProfileManagementContext ctxtWS = ProfileManagementContext.Create("https://localhost/ProfilesWebService/ProfilesWebService.asmx");

    // Load the XML string into an XML document.
    profileXMLDoc.LoadXml(xmlData);

    // Create the XML Profile, converting the XMLDocument to an XMLElement.
    ctxtWS.CreateProfile(profileXMLDoc.DocumentElement);
}

Compiling the Code

To compile the code, you must include the following namespace directives:

using Microsoft.CommerceServer.Profiles;
using System.Xml;

See Also

Other Resources

How to Create an Instance of a Profile

How to Access an Instance of a Profile

How to Serialize a Profile as XML

Profiles Concepts and Tasks