notepuddle

Using Commerce Server 2009 outside of a Web Application

February 10th, 2009comments

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:

  1. Unpup C:\Program Files\Microsoft Commerce Server 2007\Microsoft Commerce Server 2009\Site\MicrosoftCommerceDefaultSiteWithSampleData.pup to a site named ConsoleSite.
  2. Add the assemblies located at C:\Program Files\Microsoft Commerce Server 2007\Microsoft Commerce Server 2009\Assemblies as references to the project.
  3. Copy ChannelConfiguration.config (editing siteName) and MetadataDefinitions.xml from
    C:\Program Files\Microsoft Commerce Server 2007\Microsoft Commerce Server 2009\Sdk\Samples
    to the solution directory and add them to the solution.
  4. Unpack CommerceSharePointExtensibilityKit.zip from C:\Program Files\Microsoft Commerce Server 2007\Microsoft Commerce Server 2009\Sdk\Samples to C:\CommerceSharePointExtensibilityKit\.
  5. Piece together an app.config file using the configuration fragment files in the unpacked extensibility kit located at C:\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:

Console Output

You can download the example application here.

Posted in CommerceServer

« TDD and Commerce Server 2007: Custom Rollback
Vista Restarts »
discussion by DISQUS

Add New Comment

  • Subscribe:  This Thread
  • Go to:  My Comments ·  Community Page
  • Sort thread by:

    Viewing 4 Comments

    Thanks. Your comment is awaiting approval by a moderator.

    Do you already have an account? Log in and claim this comment.

      • ^
      • v
      • Permalink
      • Admin
        • Remove Post
        • Block username
        • Block email
        • Block IP address
      cmedcoff 7 months ago 1 point

      Please login to rate.

      Do you already have an account? Log in and claim this comment.

      How can I get basket operations to work from this type of console app? Aren't the pcf files needed?
      reply  edit  reblog  flag
      1 /people/cmedcoff/ /people/cmedcoff/following/
      • ^
      • v
      • Parent
      • Permalink
      • Admin
        • Remove Post
        • Block username
        • Block email
        • Block IP address
      notepuddle 7 months ago 1 point

      Please login to rate.

      Do you already have an account? Log in and claim this comment.

      You can run pipelines from a console application: http://msdn.microsoft.com/en-us/library/bb21919..., however this assumes you have control over the code that executes the pipelines. In 2007 you do; in 2009 this is abstracted away, so I don't think this is possible.
      reply  edit  reblog  flag
      1 /people/notepuddle/ /people/notepuddle/following/
      • ^
      • v
      • Permalink
      • Admin
        • Remove Post
        • Block email
        • Block IP address
      Kien Lam 1 year ago 1 point

      Please login to rate.

      Do you already have an account? Log in and claim this comment.

      Great example. I am able to run your console app. just fine. I am wondering if you have any idea why I get an FormatException when try building a wcf or web service.

      http://social.msdn.microsoft.com/Forums/en-US/c...

      Any clues on how I can solve this problem would be greatly appreciated. Thanks!
      reply  edit  reblog  flag
      /people/461220f903970a7ff096ba8310b506b0/
      • ^
      • v
      • Permalink
      • Admin
        • Remove Post
        • Block email
        • Block IP address
      Brad 1 year ago 1 point

      Please login to rate.

      Do you already have an account? Log in and claim this comment.

      Sweet, thank you very much...
      reply  edit  reblog  flag
      http://www.blfoley.com /people/21c36c98dacd1d95f9ac7475425aa8b5/
     
    discussion by DISQUS

    Add New Comment

    close ()

    status via twitter

    recent comments (follow comments)

      View Profile ยป
      Powered by Disqus · Learn more
      close Reblog this comment
      Powered by Disqus · Learn more
      blog comments powered by Disqus

      Archives

      • March 2009
      • February 2009
      • January 2009

      Categories

      • About
      • ASP.NET
      • CommerceServer
      • TDD
      • Uncategorized
      • Vista
      • VS2008