creating a profile in commerce server 2009 pragmatically
Below are step by step instruction of how to create profile in commerce server 2009 using profile service
Create an instance of the ProfilesWebService object.
Specify the credentials needed by the Profiles Web service.
Using a string variable, construct an XML representation of the profile that you want to create.
Create an XML document from the XML string.
Convert the XML document into an XML element.
Call the CreateProfile method of the ProfilesWebService object.
If you are using the Profiles Web Service, add a reference to the Profiles Web service. Example 1 assigns the Profiles Web Service the alias profileWS. For example, this is a valid reference:
Code:http://localost/ProfilesWebService/ProfilesWebService.asmx
To compile the code when you are using the Profiles Web service, you need to include these namespace directives:
Code:using System.Xml;
using System.Net;
This example creates an instance of the Profiles Web service. It uses the CreateProfile method to create a new profile, passing in the XML element structure needed to pass the default required properties. The example also builds the XML element structure by first constructing an XML string so that it can be easily read for example purposes.
Code:// Declare and set variables.
XmlDocument profileXMLDoc = new XmlDocument();
XmlElement profileXMLElement = null;
String profileXML = "";
String newGuid = "{" + Guid.NewGuid().ToString() + "}";
String password = "password";
String eMail = "someone@example.com";
String passwordQuestion = "My Question";
String passwordAnswer = "My Answer";
String accountStatus = "1";
// active
try
{
// Create an instance of the Profiles Web reference.
ProfilesWS.ProfilesWebService profileWS = new ProfilesWS.ProfilesWebService();
// Pass the correct credentials to the Web service.
profileWS.Credentials = CredentialCache.DefaultNetworkCredentials;
// Create an XML representation of the Profile.
profileXML += "<ProfileDocument>";
profileXML += " <UserObject>";
profileXML += " <GeneralInfo>";
profileXML += " <user_id>" + newGuid + "</user_id>";
profileXML += " <user_security_password>" + password + "</user_security_password>";
profileXML += " <email_address>" + eMail + "</email_address>";
profileXML += " <password_question>" + passwordQuestion + "</password_question>";
profileXML += " <password_answer>" + passwordAnswer + "</password_answer>";
profileXML += " </GeneralInfo>";
profileXML += " <AccountInfo>";
profileXML += " <account_status>" + accountStatus + "</account_status>";
profileXML += " </AccountInfo>";
profileXML += " </UserObject>";
profileXML += "</ProfileDocument>";
// Load the Profile into an XML document.
profileXMLDoc.LoadXml(profileXML);
// Convert the XML document to an XMLElement.
profileXMLElement = profileXMLDoc.DocumentElement;
// Create the Profile. The false parameter indicates that this is not created from a BizTalk adapter.
profileWS.CreateProfile(ref profileXMLElement, false);
// Write a message to the console when the profile is successfully created.
Console.WriteLine("Successfully created profile");
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}\r\nMessage: {1}", ex.GetType(), ex.ToString());
if (ex.InnerException != null)
{
Console.WriteLine("\r\nInner Exception: {0}\r\nMessage: {1}", ex.InnerException.GetType(), ex.InnerException.Message);
}
}