Wednesday, October 18, 2006

Integrating Microsoft Commerce Server 2007 and MOSS

I have just completed an interesting proof-of-concept project that showed how MOSS and Commerce Server can complement each other in provisioning an eCommerce site.

Traditionally, Commerce Server handles all commerce-type transactions, e.g. shopping carts, product catalogs, inventory, order management, etc.

MOSS picks up where Commerce Server leaves off by putting forward web content management (versioning of product information, approval workflows), some level of collaboration (e.g. product review sub-sites) and generally handling the overall branding and management of the portal.

Since both products leverage on ASP.NET 2.0, they integrate really nicely together. Kind of like building an eCommerce site on steroids :-)

The trickiest bit, which suprisingly turned out to be a really smooth ride, was how to get MOSS linked up to Commerce Server. For an integrated solution, we absolutely needed to call Commerce Server APIs from MOSS. To add an additional level of complexity to the problem, we were also required to authenticate users using Commerce Server's UpmMembershipProvider.

And before I forget what we went through, here's how it was done.

Getting MOSS to recognize Commerce Server's APIs
The first step was to merge the configuration files of both the Commerce Server and SharePoint site. Since we were using MOSS to manage the branding of the site, it made sense to make it the customer facing app and modify it's web.config file to include Commerce Server's configurations. These are the parts that need to be copied over (I'm going to use square brackets instead of angle brackets here as Blogger does not handle angles very well):

1. Everything in the [sectionGroup name="CommerceServer]" tag
2. Everything in the ["CommerceServer"] tag
3. All the commerce server specific handlers in the [httpModules] tag - Includes "CommerceApplication" all the way down to "CommerceDataWarehouseAuthenticationModule"
4. All the commerce server [assemblies] listed in the [compilation] tag.

Next, we copied all the CommerceServer library files to the bin directory. List of files included:
a. CommerceMessageManager.dll
b. The "de-DE", "en-us", "fr-fr", ja-JP" sub folders.

Copy also the following files from the root directory of the Commerce Server site to the root directory of the SharePoint site:
a. csapp.ini
b. OrderObjectMappings.xml
c. OrderPipelineMappings.xml
d. as well as the entire "pipelines" folder.

And voila! With that, we could use the Commerce Server API from any page within MOSS. E.g. CommerceContext.Current should now return a valid instance.

Implementing the UpmMembershipProvider on a MOSS site
To capitalize on Commerce Server's Profiler, we needed to implement the UpmMembershipProvider on the MOSS site. This part of the setup has been nicely documented in this newsgroup post by Amy.

However, it's probably worthwhile to note that if you're using the email address as the loginID, you could distill it down to the following steps:

1. Add the [membership] tag, for example: (note, I've replaced angle brakets with square brackets).

[membership defaultProvider="UpmMembershipProvider"]
[clear /]
[add applicationName="MyAppName" enablePasswordRetrieval="false" enablePasswordReset="true" logonNameProperty="GeneralInfo.email_address" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" enableCreateDate="true" enableEmailAddress="true" enableLastLoginDate="true" profileDefinition="UserObject" passwordFormat="Hashed" name="UpmMembershipProvider" type="Microsoft.CommerceServer.Runtime.Profiles.UpmMembershipProvider" /]

2. Uncomment, or add (if it's not already present) the [profiles] tag in the [CommerceServer] section of the web.config file.

3. And before you can add the first administrator to the site. You will need to complete all the steps above (yes, even the part about merging the web.config file) on the SharePoint Central Administration website as well.

4. Finally, use SharePoint Central Administration to apply forms authentication to the site in question and specify "UpmMembershipProvider" as the membership provider.

The biggest headaches that arose from the applying the UpmMembershipProvider were typos and missing commerce server tags. Make a tiny mistake and you will find that the login form gets stuck in a loop, regardless of the userid and password entered. When I forgot to add the commerce server [assemblies] to the web.config file, it took me 2 agonizing hours before I realised what was wrong. Erk.

The best part is, once its setup, integrating Commerce Server and MOSS is a breeze. After the initial setup is done, you can easily create SharePoint web parts and user controls using Commerce Server's API to build some really neat features.

Food for thought: It would really be nice to have an "Enable as Commerce Site" button in SharePoint Designer like the "Enable as CMS site" button we had in VS.NET for MCMS. That will be really neat!