This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.
|
The Web Means Business with the Microsoft Commerce Server
Marco Tabini |
As electronic commerce-mania grips a frenzied nation of Webheads, many sites have turned to Microsoft Commerce Server as an easy-to-implement solution for their storefront woes. |
It's no wonder that so many companies these days consider electronic commerce (EC) their future. What's surprising is how few online stores go beyond the basics. Many vendors consider a bunch of semifunctional Perl scripts an online storedefinitely a stretch considering the complexity of the Internet. EC applications based on custom engines like these are usually built as solutions to specific problems and lack the flexibility and robustness to accommodate a dynamic marketplace.
As a result, a good percentage of the commerce sites out there are like the Mona Lisa without her famous smile: plain and incomplete. Add the general public's notion that online shopping is not securedespite the fact that it's as safe as any form of commerceand you'll see why EC hasn't taken off so rapidly. Earlier this year, Microsoft® released Commerce Server 2.0 (MSCS) as a component of the Site Server Enterprise Edition suite. MSCS is a significant improvement over Microsoft Merchant Server 1.0, Microsoft's previous EC software and many companies already support MSCS as their primary EC solution. The screenshots presented here are taken from the online software store Softmania (http://www.softmania.com), which I helped develop. EC comes in two flavors: business-to-consumer and business-to-business. The consumer who is shopping online wants the experience to be easy, convenient, and secure. Online store operators, on the other hand, see the Internet not only as a channel for reaching their customers, but also as an inexpensive medium for communicating with their suppliers. For them, a commerce solution must be flexible, easy to maintain, and ready to be integrated with existing business-to-business standards such as Electronic Data Interchange. MSCS provides excellent support for all the aspects of business-to-consumer commerce, and although the system doesn't directly handle business-to-business transactions, it provides enough customizability to let the developer take care of the problem. Microsoft is currently working on the Commerce Interchange platform, which will integrate business-to-business transactions in future versions of MSCS.
Architectural Overview
|
In MSCS, while each store has its own database, ASP-powered Web site, and OPP, it shares the functionality of the server with all the other stores. Store sites are divided into two main sections: shops and managers. A shop contains the interface that is usually accessed by customers through the net; this includes catalog browsing, order collecting, and so on. A manager usually cannot be accessed by users. It handles the store's maintenance issues, such as catalog editing, order viewing, and customer statistics. A store is, therefore, a fully integrated and self-contained ASP application whose parts can be accessed from anywhere through the Internet. No need to worry, though; MSCS managers can be protected using standard Windows NT security, and are therefore as safe as your passwords.
Managing Stores
General maintenance of all the stores installed on a computer is done through an ASP-based application called Server Manager. This utility is useful for controlling all the sites through a single command center. It can be used to open or close a store (when a store is closed, it normally does not accept orders), to access its manager or shop section, to create new stores, and to copy or delete existing ones. Figure 2 shows the Server Manager's main page.
Whenever you want to create a new store, the Store Foundation Wizard (shown in Figure 3) guides you through the necessary steps. You are asked the name of the store you want to create, your choice of database and datasource, and the login ID that will function as administrator for the Store Manager. The wizard creates all the structures required by the store to work properly, including a standard OPP. However, no actual HTML code is generated so that, in theory, developers can write their own site interfaces from scratch.
Figure 3: Store Foundation Wizard |
Most programmers will use the StoreBuilder Wizard instead (see Figure 4). It's accessible through the Store Manager of a newly created store. After just a handful of clicks, you'll end up with a fully functional MSCS store that even includes its own graphics and support for the desired locale (taxes included). |
Figure 4: StoreBuilder Wizard |
Although stores created with Store Foundation Wizard and StoreBuilder Wizard need significant customization, particularly in terms of display, their structure is surprisingly complex. They are complete in many ways, and for a fairly simple EC site they can be used right as they come out of the wizard processes. Figures 5, 6, and 7 are taken from the Marco Tabini Store (OK, so it's not the most exciting name on earth). As you will notice, they are significantly simpler than a commercial site like Softmania (shown in Figures 8, 9, and 10). Yet it is possible to buy Marco Tabini-related products with the click of a mouse. The store will take care of computing taxes, shipping and handling fees, and ensuring that the customer provides a valid credit card during payment. |
Figure 5: Marco Tabini Store |
Figure 6: Selecting a Product |
Figure 7: Buying a Product |
Thus, in five minutes (even less once you know your way through the wizards) it is possible to create a site that would have taken much longer to develop from scratch and that would have left the client with a very basic store and a lot less money in their pocket. Instead, you can use it as a starting point, leaving an incredible amount of time for customization and improvementnot to mention higher margins! |
Figure 8: Softmania's Online Store |
Figure 9: Games/Entertainment Page |
Figure 10: Buying on Action Game |
You may have been wondering what buying something from your site looks like from your customers' point of view. Chances are your store will look a lot like a department store, even though you may sell only one type of product. During their visit, customers will click around the various sections of the store, and hopefully will add some of the products you offer to their Virtual Shopping Basket (VSB). The VSB can be reviewed at any time and the items that it contains can be removed or their quantity can be changed. Figure 11 shows Softmania's VSB. Softmania calls it a shopping cart, but the functionality is exactly the same. |
Figure1: Softmania's Shopping Cart |
Once customers make up their minds, they might decide to place an order. They will be asked for personal information such as shipping and billing addresses and payment information. MSCS will process this data according to the parameters specified by the developer to either accept or refuse the order.
Server Integration
|
|
Afterward, the command |
|
will print "Testing" on the page.
Accessing the Database
Figure 16 contains a simple script that creates a Content object, then adds a DataSource object and two queries to it. One of the queries is then executed and the resulting records written to the browser. Figure 17 shows the output of the script.
Handling Shoppers
Sprechen Sie Englisch?
HTML Made Easy (Almost)
The Microsoft Wallet
|
Figure 22: Using the Wallet |
As you can see in Figure 22, using the Wallet is simple. The user will typically specify an address in the Address Selector and a payment method in the Payment Selector. All the information is stored locally and, in the case of payment data, encrypted against a password specified by the user. By default, the Wallet will pop up a notification window whenever an address is about to be released and will ask for a password before transmitting any payment data. Several sets of information can be stored in a single Wallet and retrieved or edited individually (see Figure 23). |
Figure 23: Payment Methods |
Many of the Wallet's interface elements can be customized, including the font face used to display text information and the color of several interface items. The code in Figure 24 will produce an HTML page that contains both selectors and three buttons that will alter their appearance dynamically through scripting. Since it uses VBScript, it will work only on Internet Explorer, and I am sure that you will be able to produce some rather, um, unusual results with it. Although the Wallet supports all major credit cards by default (VISA, MasterCard, American Express, and Discover), you might want to implement other payment methods to satisfy special needs: bank accounts, debit cards, or private label credit cards, and so on. This can be done by writing Wallet plug-ins using Visual C++ and the Commerce SDK, a rich collection of tools and samples that can also be used to write OPP components. The downside of the Wallet is obviously that, unless you have Internet Explorer 4.0, it definitely doesn't come with your browser and has to be downloaded off the Microsoft Web site. |
Figure 25: Page without Wallet Link |
For those users who have trouble with the Wallet, or simply do not want to install it, MSCS provides support for what I call the Poor Man's Walletthe dreaded HTML forms. Figure 25 shows the same page displayed in Figure 23 when the user selects the "Click here if you have problems with the Wallet" link. It isat least to mea very depressing view after seeing the beauty of the Wallet, but when you have a 28.8Kbps connection it is certainly less depressing (and expensive) than going out for a coffee while the browser downloads components. Those of you attentive to details will have already noticed that by mentioning how the Wallet is an ActiveX control, I have suddenly reduced the potential Wallet audience to a mere 40 percent (but rising) of all the Web browsers. Well, do not despairMicrosoft provides a version of the Wallet intended for Netscape software. The tricky part comes when you want to install a different version of each plug-in according to which browser the user has. You will need to implement some kind of browser recognition to give your store a certain solidity. If the visiting browser does not support either ActiveX or Netscape plug-ins (or if you have doubts whether it does), you will have to use forms. Browser recognition is done through the MSWC.BrowserType standard ASP component, which simply compares server variables against a table contained in the Browscap.ini file usually located in the C:\Winnt\System32\Inetsrv\Asp\ Cmpnts directory on the server's hard drive. The problem with this technique is that the Browscap.ini file that comes with the ASP installation pack is not exactly up to date, resulting in obvious mistakes (see Figure 26 for an example). |
Figure 26: Shipping Information |
Microsoft used to provide regular updates to the Browscap.ini file that could be downloaded from their Web site, but the most up-to-date version is distributed by CyScape, Inc. (http://www.cyscape.com). CyScape is also working on a new component that will simplify the process of browser recognition. While I am writing this article, the component is in the first stages of its beta testing, and should be available soon.
Order Processing
Using the OPP
An MSCS store invokes the OPP several times during the purchase process, although sometimes it doesn't require all of its steps to be executed. Figure 27 also illustrates how stages have been grouped according to three execution modes, which correspond to specific actions on behalf of the customer. Product Mode is used when the user alters the content of the VSB (that is, by adding or removing an item). Plan Mode is used to verify that all the information contained in the OrderForm is correct and to compute all the costs related to the order (shipping, taxes, and so on). Purchase Mode is used whenever a purchase has to be completed. It executes all the stages of the OPP and attempts to commit the order to the database. The components that run inside the OPP are COM objects that implement several interfaces and support freethreaded execution. Since it is not possible to control the execution flow inside the OPP (all the components belonging to the same execution mode are always executed), MSCS uses a collaborative model to determine how each component affects the OrderForm parameters. Whenever the OPP is invoked, it automatically resets all the OrderForm parameters that are to be modified inside the pipeline by setting them to null. Subsequently, a component should only change a parameter if its value is still null. Thus, the order in which components are executed within the same stage is very important. Although this model has its disadvantages, it helps keep the OPP simple and does not cause any trouble as long as you use compliant components.
Writing Your Own OPP
Components
|
Figure 28: Pipeline Editor |
There would be no justice, however, if Microsoft didn't provide the truly Web-based Pipeline Editor that you can see in Figure 29. This ASP-based application has almost the same functionality as the Win32-based version, although the interface is slightly more cumbersome. It comes in handy when you have to configure your OPP remotely, as
often happens for security reasons. |
Figure 29: Web-based Pipeline Editor |
MSCS comes with 33 built-in OPP components whose use varies from tax calculation to the implementation of complex promotions. Although they are more than enough for the creation of a relatively complex store, sooner or later you will find yourself in need of something that is more specific than what MSCS covers. The obvious solution is to write your own components from scratch, using a compiler that supports both the creation of COM objects and the Windows freethreaded execution model. Unfortunately, this rules out using Visual Basic®, which only allows for the creation of apartment-threaded COM objects. The next choice would probably be Visual C++ and the Active Template Library (ATL), a more powerful but also more complicated combination. |
Figure 30: Scriptor Component |
The easiest way to write your own components is by using the Scriptor component shown in Figure 30, which provides a programming environment that runs Microsoft Scripting Engine (MSE) compatible code. MSE is the same engine that ASP uses, which means that you can write your components in your favorite scripting language, such as VBScript or JScript. The script to be executed can be specified as a parameter, in which case its length is limited to 2,048 characters, or it can be included in an external text file.
Writing a Sample Component
|
|
Config contains information about the script (see Figure 33), as well as
any parameter that has been specified in the Parameters section of the component configuration. Flags is
a debug mode flag and should be
equal to 1. Context is a reference to a Context objectbasically a set of ASP components. For example, any ASP page receives by default a Context object that contains several components, such as the Server, the Request, the Application, and so on. The objects included in an OPP component's Context object (see Figure 34) are fairly different from the ones available in an ASP page, but they contain everything that the component needs to manipulate the database and the OrderForm. MSCSOpen and MSCSClose are optional functions that can be run before the execution of MSCSExecution and right before the destruction of the object. Figure 35 shows the code for the OrderMagnitude component. The component executes a database query to find out what categories are defined in the OrderCategories table, then calculates the number of items in the order by simply adding the quantity for each product. Finally, the resulting number is checked again. Each category and the OrderCategory name/value pair in the OrderForm is set to the name of the correct category. If all the checks fail, the OrderCategory parameter is set to "Unknown Category." The MSCSExecute function must return a value to indicate whether its execution was successful (see Figure 36). Returning a serious error level can result in interrupting the execution of the OPP, while some execution modes tolerate warnings. A component can also return error messages to the user by storing them in the OrderForm.ShippingErrors and OrderForm.PurchaseErrors collections. Their contents will usually be dumped by the ASP pages of the store when the customer tries to proceed with the purchase.
Running and Debugging the OPP
|
Figure 37: Checking an Order |
As often happens, this wasn't true at the very beginning. No matter how many items were ordered, I always got the same result: the component thought that my orders always had zero items in them and assigned them to the first category. To solve the problem, I simply had to open up my store's Global.asa file and uncomment the following line that MSCS created for me as a standard part of the store: |
|
This way, the OPP will log the actions performed by all the components on the OrderForm. A quick look at Figure 38 shows that I had mistyped the word quantity as quntity and I was trying to access a parameter of the OrderForm that obviously didn't exist. Fixing the bug was a breeze, and afterward the component ran just fine. |
Figure 38: Logging the Actions |
Always remember to turn off the OPP logging by commenting the line in Global.asa again, or you will soon find yourself with a logfile of several megabytes that can easily make your store unusable.
Conclusion
|
From the March 1998 issue of Microsoft Interactive Developer.