How to Create an OrderManagementContext Object
For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.
The OrderManagementContext object is the starting point for performing data management operations on all objects in the Orders System. You must create an OrderManagementContext object before you can access any of the other objects in the Microsoft.CommerceServer.Orders namespace.
To create an OrderManagementContext object, you must first create an agent, which is an object that provides access to the Orders System. You can create two types of agents:
An OrderSiteAgent object provides in-process (in-proc) access to the Orders System.
An OrderServiceAgent object provides out-of-process (out-of-proc) access to the Orders System by using the Orders Web service.
This topic includes procedures for creating an OrderManagementContext object that will access the Orders System both in-proc and out-of-proc. It also includes sample code that illustrates both cases.
To create an OrderManagementContext that accesses the Orders System in-proc
Create a new project in Visual Studio.
Add the following references:
Microsoft.CommerceServer.CrossTierTypes
Microsoft.CommerceServer.Orders.CrossTierTypes
Add using directives for the following namespaces:
Create a new OrderSiteAgent object and pass the name of the site that the agent should connect to.
Create a new OrderManagementContext object and pass the OrderSiteAgent object to the Create method of the OrderManagementContext object.
To create an OrderManagementContext that accesses the Orders System out-of-proc
Create a new project in Visual Studio.
Add the following references:
Microsoft.CommerceServer.CrossTierTypes
Microsoft.CommerceServer.Orders.CrossTierTypes
Add using directives for the following namespaces:
Create a new OrderServiceAgent object and provide the URL to the Orders Web service.
Create a new OrderManagementContext object and pass the OrderServiceAgent object to the Create method of the OrderManagementContext object.
Example
The following code example illustrates how to create an OrderManagementContext object that accesses the Orders System in-proc. To access the Orders System out-of-proc, comment out the line that creates the OrderSiteAgent, and uncomment the line that creates the OrderServiceAgent.
Note
You must make changes in the code to match your own site. In the line that creates the OrderSiteAgent, replace the argument "StarterSite" with the name of your own site.
Note
In the line that creates the OrderServiceAgent, replace the URL with the URL for your Orders Web service.
using System;
using System.Data;
using System.Globalization;
using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Orders;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
// Create the OrderManagementContext. This requires an
// agent object to provide access to the Orders System.
// The agent will be created in local mode, which
// enables direct access to the Orders System. (The agent
// can also be created in agent mode, which enables
// access to the Orders System by using the Orders Web
// service.) To use agent mode instead of local mode,
// comment out the line that initializes ordersAgent as an
// OrderSiteAgent object, and uncomment the line that
// initializes ordersAgent as an OrderServiceAgent object.
// The remaining code remains the same.
// You might notice a delay while Commerce Server creates
// the OrderServiceAgent object. The delay occurs because
// the Orders Web service must be started.
// In the following, replace "StarterSite" with the name
// of your site.
OrderSiteAgent ordersAgent = new
OrderSiteAgent("StarterSite");
// If you want to access the Orders System out-of-proc,
// uncomment the following line and replace
// the URL with the URL to your Orders Web service.
// OrderServiceAgent ordersAgent = new OrderServiceAgent("https://localhost/ordersWebService/ordersWebService.asmx");
OrderManagementContext orderManagementContext = OrderManagementContext.Create(ordersAgent);
} // end Main
} // end class Program
} // end namespace
See Also
Other Resources
Understanding the Different Types of Commerce Server APIs