Geeks With Blogs
A Point To Share A journey through Microsoft Commerce Server and other .NET platforms

When Commerce Server 2009 was released, it introduced a new API (commonly known as Multi Channel Commerce Foundation) based on the latest technology stack at the time. One of the biggest changes was the basis of an n-tier architect, based on WCF, which for the first time removed the Commerce Server dependencies from the web/presentation tier, and allowed all of the logic to be encapsulated on a separate application layer. In modern day architecture this becomes important when the presentation tier (web farm) needs to scale to meet the demand of richer user interfaces.

As I review more and more Commerce Server implementations, it seems that a lot of people do not realise the API they are working on is simply a WCF net.pipe end point, fully capable of being hosted as an externally-facing WCF endpoint.  What may be putting a few people off is this message placed on MSDN:


While WCF is not supported as an enabled service in this release, it has not been disabled.

The interpretation for this is sometimes misconstrued, and taken to mean that WCF is not a recommended way forward. The full WCF implementation is NOT supported, this is primarily because Commerce Server 2009 still has dependencies on the HTTPContext within its runtimes. Therefore if you enabled a WCF endpoint without access to HTTPContext you would need to run in a SharedContext = false mode and manually manage all of the Commerce Server runtime dependencies.   When SharedContext is set to false, you can not also extend any of the pipeline objects, such as the order form making extensibility difficult to achieve.

What is supported within Commerce Server 2009 however is running within SharedContext mode on an end point hosted within IIS with access to HTTPContext. Security is however questionable at this point, so currently I have only every deployed this architecture to separate architectural tiers – and as of yet have never exposed this end point across the Internet.

So how is this achieved?

As the whole Multi Channel Commerce Foundation API is built using WCF, getting up as an IIS hosted end point and running is very quick and easy to achieve. Here are the total amount of steps required:

1) Create an WCF endpoint (.svc) in your solution. Remove the code-behind file, and replace it with the following

   1: <%@ ServiceHost Language="C#" Debug="true" Service="Microsoft.Commerce.Broker.OperationService" %>


2) Define the endpoint in your web.config, making sure it is an endpoint that supports ASP.NET Compatibility Mode (thus allowing access to the web.config)

   1: <system.serviceModel>
   2:         <diagnostics etwProviderId="c1ad3c65-3924-4089-881f-b7aa3fe2a5fd">
   3:             <messageLogging maxMessagesToLog="30000" logEntireMessage="true" logMessagesAtServiceLevel="false" logMalformedMessages="true" logMessagesAtTransportLevel="true">
   4:                 <filters>
   5:                     <clear/>
   6:                 </filters>
   7:             </messageLogging>
   8:             <endToEndTracing propagateActivity="false" messageFlowTracing="false"/>
   9:         </diagnostics>
  10:         <bindings>
  11:             <webHttpBinding>
  12:                 <binding name="WindowsAuth">
  13:                     <security mode="TransportCredentialOnly">
  14:                         <transport clientCredentialType="Windows"/>
  15:                     </security>
  16:                 </binding>
  17:             </webHttpBinding>
  18:         </bindings>
  19:         <services>
  20:             <service name="Microsoft.Commerce.Broker.OperationService">
  21:                 <endpoint address="" behaviorConfiguration="AspNetAjaxBehavior" binding="webHttpBinding" bindingName="WindowsAuth" bindingConfiguration="" name="CommerceServerBroker" contract="Microsoft.Commerce.Contracts.IOperationService"/>
  22:                 <endpoint address="mex" binding="mexHttpBinding" contract="Microsoft.Commerce.Contracts.IOperationService"/>
  23:             </service>
  24:         </services>
  25:         <behaviors>
  26:             <endpointBehaviors>
  27:                 <behavior name="AspNetAjaxBehavior">
  28:                     <enableWebScript/>
  29:                 </behavior>
  30:             </endpointBehaviors>
  31:             <serviceBehaviors>
  32:                 <behavior name="">
  33:                     <serviceMetadata httpGetEnabled="true"/>
  34:                     <serviceDebug includeExceptionDetailInFaults="true"/>
  35:                     <etwTracking profileName="HealthMonitoring Tracking Profile"/>
  36:                 </behavior>
  37:             </serviceBehaviors>
  38:         </behaviors>
  39:         <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false"/>
  40:     </system.serviceModel>


3) Add the necessary runtime elements to the web application, including the HTTPModules, and Commerce Server settings withing the web.confg. Also add in your pipelines, Channel.Config, metadatadefintions.xml, OrderObjectMappings.xml, OrderPipelineMappins.xml and any required assemblies and resource files.

4) That’s it your done! You should now be able to create a completely new project, Add a Service Reference, and you should be able to create queries against Commerce Server, as per the documentation – but using the serialized data contracts.

What’s more, is you no longer will need to use ASP.NET as your presentation tier,  as long as the solution conforms to the security requirements you can build any type of front end you require. Thus forming the basis of your multi-channel solution.

Update: The demo solution code can now be found here.

Posted on Monday, August 16, 2010 9:59 AM | Back to top

Comments on this post: Using Commerce Server 2009 in n-Tier Architecture

# re: Using Commerce Server 2009 in n-Tier Architecture
Requesting Gravatar...
We're working along the same path in my current project. Our plan is to flow the user using claims and claims aware WCF services.
Left by Niklas on Aug 26, 2010 10:37 PM

# re: Using Commerce Server 2009 in n-Tier Architecture
Requesting Gravatar...
When are you planning to upload a sample solution? We're having some issues with WCF and Commerce Server 2009 working together.
Left by Alex on Sep 14, 2010 1:05 PM

Your comment:
 (will show your gravatar)

Copyright © Lewis Benge | Powered by: