Share via


How to Create a Campaign in Agent Mode

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

Creating a campaign by using the Marketing Service agent requires an instance of MarketingServiceAgent. All your code interacts with the Marketing Web service through this object. You must create an instance of Customer and use the IndustryCodeManager class to create an instance of IndustryCode.

Note

You can use this code both remotely and on the computer that is running Commerce Server.

To create an Agent Mode campaign

  1. Create a MarketingServiceAgent object. This object contains the authentication information needed to interact with the Marketing Web service.

  2. Create a MarketingContext object. You use this object to interact with the Marketing System APIs.

  3. Create an IndustryCode object. This object represents an industry, such as aviation or food.

  4. Create a Customer object to use for the campaign.

  5. Use the Industry property of the Customer object to assign the IndustryCode to the Customer.

  6. Create a Campaign object with the Id property of the Customer object.

  7. Set the properties of the Campaign object.

Example

The following code sample first creates an instance of the Marketing System agent object, creates an industry code by using the industry code manager, creates a new customer, assigns the industry code to the customer, and then creates a new campaign associated with the customer ID.

using System;
using Microsoft.CommerceServer.Marketing;

namespace ConsoleApplication1
{
    // This code requires you to add the following references:
    // Microsoft.CommerceServer.CrossTierTypes
    // Microsoft.CommerceServer.Marketing.CrossTierTypes

    // Make sure that your user account has sufficient Marketing permissions to perform
    // these operations.
    
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // Set the URL to the Web service.
                string campaignServiceUrl = @"https://localhost/MarketingWebService/MarketingWebService.asmx";
                // Create an instance of the Marketing System agent.
                MarketingServiceAgent ma = new MarketingServiceAgent(campaignServiceUrl);
                MarketingContext marketingSystem = MarketingContext.Create(ma);

                // Create a new industry code.
                IndustryCodeManager im = marketingSystem.IndustryCodes;
                IndustryCode ic = im.NewIndustryCode();
                ic.Name = "Paper Products";
                ic.Save();
               
                // Create a new customer to use for the campaign.
                Customer cu = marketingSystem.Customers.NewCustomer();

                // Set the minimum required properties.
                cu.Name = "Example Customer";
                cu.Industry = ic.Name;

                // Save the customer.
                cu.Save(true);
                              
                // Create the campaign.
                Campaign ca = marketingSystem.Campaigns.NewCampaign(cu.Id);
                
                // Set the minimum required campaign properties.
                ca.Name = "Example Campaign";
                DateTime startdate=DateTime.Now;
                DateTime enddate=startdate.AddDays(30);
                ca.StartDate = startdate;
                ca.EndDate = enddate;
                ca.EventTypeName = "Click";

                // Save the campaign.
                ca.Save(true);

                // Success!
                Console.WriteLine("Successfully created campaign name: {0}", ca.Name);
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}\r\nMessage: {1}", ex.GetType(), ex.Message);
                if (ex.InnerException != null)
                {
                    Console.WriteLine("\r\nInner Exception: {0}\r\nMessage: {1}", ex.InnerException.GetType(), ex.InnerException.Message);
                }
                Console.ReadLine();
            }
        }
    }
}

See Also

Other Resources

Understanding the Different Types of Commerce Server APIs