Archive for February, 2009
Using Commerce Server 2009 outside of a Web Application
Tuesday, February 10th, 20096 comments
If you try running Commerce Server 2009 outside of a web application you’ll likely encounter a few exceptions along the way. The hurdles are setting up configuration settings and initializing the context objects.
Setting up a Console Application
I created an example to query a catalog product, using the following steps for setting up a Visual Studio 2008 Console Application with Commerce Server 2009 RC1:
- Unpup
C:\Program Files\Microsoft Commerce Server 2007\Microsoft Commerce Server 2009\Site\MicrosoftCommerceDefaultSiteWithSampleData.pupto a site namedConsoleSite. - Add the assemblies located at
C:\Program Files\Microsoft Commerce Server 2007\Microsoft Commerce Server 2009\Assembliesas references to the project. - Copy
ChannelConfiguration.config(editing siteName) andMetadataDefinitions.xmlfromto the solution directory and add them to the solution.
C:\Program Files\Microsoft Commerce Server 2007\Microsoft Commerce Server 2009\Sdk\Samples - Unpack
CommerceSharePointExtensibilityKit.zipfromC:\Program Files\Microsoft Commerce Server 2007\Microsoft Commerce Server 2009\Sdk\SamplestoC:\CommerceSharePointExtensibilityKit\. - Piece together an
app.configfile using the configuration fragment files in the unpacked extensibility kit located atC:\CommerceSharePointExtensibilityKit\SharePointCommon\FeatureActivation\DefaultConfigs\.
Initializing Context Objects
In Commerce Server 2007 you have to manually create each subsystem context during your application initialization process, when executing outside of a web site. In Commerce Server 2009 context initialization is controlled by the useSharedCommerceContexts attribute in the channel configuration file:
<ServiceConfiguration useSharedCommerceContexts="true">
...
</ServiceConfiguration>
The default value for useSharedCommerceContexts is true. If you try running your non-web application with this setting, you will see the following error in the event log:
...
Microsoft.Commerce.Providers.Exceptions.ContextCreationException, ...
Message : Configuration specifies useSharedCommerceContexts=true however this is only valid for a Commerce Server enabled web site runtime environment.
...
You need to set this value to false and add some additional configuration elements.
Searching the CS2009 documentation for useSharedCommerceContexts reveals one result explaining a work around when specifying useSharedCommerceContexts="false". It outlines additional configuration settings to include in the channel configuration file and displays the following warning regarding useSharedCommerceContexts:
Currently only “true” is supported, meaning that Commerce Server 2009 is running as a shared Commerce Server resource
FWIW, I’ve been using this technique for automated unit testing on my current project without any issues.
The example I created queries the Adventure Works catalog for a product and displays a few of its properties. Here’s what the output looks like:

You can download the example application here.
