Commerce Server General - ProfileContext

This is Interesting: Free IT Magazines  
Home > Archive > Commerce Server General > October 2006 > ProfileContext





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author ProfileContext
Xcel

2006-10-13, 1:20 pm

I can't seem to get the following code to run - which is directly from the
documentation. The code seem to fail when it tries to create the
ProfileContext - stating there is a null instance. My ulitimate goal here is
to retrieve a User Profile and get the Credit Card number and decrypt for use
in a integration process.

Please Advise.



ProfileContext profiles = CommerceContext.Current.ProfileSystem;

// To make the example work, create a new instance of a
// profile, so that we know its profileID.

string profileID = Guid.NewGuid().ToString();
CommerceProfile newProfile = profiles.CreateProfile(profileID,
"Address");
newProfile["GeneralInfo.address_name"].Value = "Home";
newProfile["GeneralInfo.address_line1"].Value = "street";
newProfile["GeneralInfo.region_code"].Value = "region";
newProfile["GeneralInfo.postal_code"].Value = "code";
newProfile["GeneralInfo.country_code"].Value = "country";
newProfile.Update();

// Retrieve the profile instance.

Profile myProfile = profiles.GetProfile(profileID, "Address");

// Get the value of a property of the profile instance.

string postalCode =
myProfile["GeneralInfo.postal_code"].Value.ToString();

// Set the value of a property of the profile instance.

myProfile["GeneralInfo.postal_code"].Value = "12345";

// Commit the changed postal code to the underlying data
// storage.

myProfile.Update();

// Delete the instance of the profile.

profiles.DeleteProfile(profileID, "Address");

Joseph Johnson

2006-10-13, 7:33 pm

Xcel,

The segment of code:

CommerceContext.Current.ProfileSystem;

Cannot be accessed outside of an established http context, so you can't use
this code from a console application, it will only work in a correctly
configured asp.net application.

You should be able to create a ProfileContext/ProfileManagementContext using
an agent pattern to "hook into" the Commerce Server system. Nihit Kaul has
a blog entry from May that explains how to use this agent pattern to create
an order context, so I'm assuming you could do something similiar to get a
profile context.

http://blogs.msdn.com/nihitk/Default.aspx?p=2

Joe

"Xcel" <Xcel@discussions.microsoft.com> wrote in message
news:34583408-D755-467E-A02D-C75ECDB503F3@microsoft.com...
>I can't seem to get the following code to run - which is directly from the
> documentation. The code seem to fail when it tries to create the
> ProfileContext - stating there is a null instance. My ulitimate goal here
> is
> to retrieve a User Profile and get the Credit Card number and decrypt for
> use
> in a integration process.
>
> Please Advise.
>
>
>
> ProfileContext profiles = CommerceContext.Current.ProfileSystem;
>
> // To make the example work, create a new instance of a
> // profile, so that we know its profileID.
>
> string profileID = Guid.NewGuid().ToString();
> CommerceProfile newProfile = profiles.CreateProfile(profileID,
> "Address");
> newProfile["GeneralInfo.address_name"].Value = "Home";
> newProfile["GeneralInfo.address_line1"].Value = "street";
> newProfile["GeneralInfo.region_code"].Value = "region";
> newProfile["GeneralInfo.postal_code"].Value = "code";
> newProfile["GeneralInfo.country_code"].Value = "country";
> newProfile.Update();
>
> // Retrieve the profile instance.
>
> Profile myProfile = profiles.GetProfile(profileID, "Address");
>
> // Get the value of a property of the profile instance.
>
> string postalCode =
> myProfile["GeneralInfo.postal_code"].Value.ToString();
>
> // Set the value of a property of the profile instance.
>
> myProfile["GeneralInfo.postal_code"].Value = "12345";
>
> // Commit the changed postal code to the underlying data
> // storage.
>
> myProfile.Update();
>
> // Delete the instance of the profile.
>
> profiles.DeleteProfile(profileID, "Address");
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com