Sample: Create, read, update, and delete marketing results

 

Applies To: Dynamics Marketing

This sample code is for Microsoft Dynamics Marketing. The sample code can be found in the following location after you download and install the Microsoft Dynamics Marketing SDK:

Samples\CS\MarketingResultSample

Requirements

Note

This sample works with your live production data. It might create real data in your Microsoft Dynamics Marketing environment.

Demonstrates

This sample demonstrates how to create, retrieve, update, and delete a marketing result using Dynamics Marketing.

Example

namespace Microsoft.Dynamics.Marketing.SDK.Samples.MarketingResultSample
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Globalization;
    using System.Linq;
    using Microsoft.Dynamics.Marketing.SDK.Common;
    using Microsoft.Dynamics.Marketing.SDK.Messages;
    using Microsoft.Dynamics.Marketing.SDK.Messages.MarketingResult;
    using Microsoft.Dynamics.Marketing.SDK.Model;
    using Microsoft.Dynamics.Marketing.SDK.Samples.SdkClient;
    using Microsoft.Dynamics.Marketing.SDK.Samples.SdkSample;

    /// <summary>
    /// Demonstrates how to perform create, read, update, and delete operations on the Marketing Result entity.
    /// </summary>
    /// <remarks>
    /// Depending on which part of the sample you run, some prior set up is required.
    /// For all of the options in this sample you must have the SDK configured with your Microsoft Azure Service Bus queues on the Integration Options page in Microsoft Dynamics Marketing.
    /// You must also have permissions enabled for results.
    /// </remarks>
    public class MarketingResultSample : SdkSample
    {
        private bool updateRequestSent;

        /// <summary>
        /// Starting point for the sample.
        /// </summary>
        /// <param name="args">Arguments needed for authentication.</param>
        public static void Main(string[] args)
        {
            try
            {
                // This creates the QueueClientProvider that connects to the queues, tests them, and then provides them to the client when needed.
                var queueClientProvider = CreateQueueClientProviderFromArgs(args);

                // This runs the sample that shows a menu of possible requests.
                var sample = new MarketingResultSample(queueClientProvider);
                sample.Run();
            }
            catch (Exception ex)
            {
                MarketingResultSample.WriteException(ex);
                Console.WriteLine("Press Enter key to exit.");
                Console.ReadLine();
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="MarketingResultSample"/> class.
        /// </summary>
        /// <param name="queueClientProvider">
        /// The QueueClientProvider that’s set up to connect to the SDK queues configured in Microsoft Dynamics Marketing.
        /// </param>
        public MarketingResultSample(IQueueClientProvider queueClientProvider)
        {
            this.updateRequestSent = false;
            var responseHandlerMapping = new Dictionary<Type, Client.ResponseHandler>
            {
                { typeof(RetrieveMarketingResultResponse), this.ProcessRetrieveMarketingResultResponse },
                { typeof(RetrieveMarketingResultsResponse), this.ProcessRetrieveMarketingResultsResponse },
                { typeof(CreateOrUpdateMarketingResultResponse), this.ProcessCreateOrUpdateMarketingResultResponse },
                { typeof(DeleteMarketingResultResponse), this.ProcessDeleteMarketingResultResponse },
                { typeof(RetrieveMarketingResultTypesResponse), this.ProcessRetrieveMarketingResultTypesResponse },
                { typeof(CreateOrUpdateMarketingResultsResponse), this.ProcessCreateOrUpdateMarketingResultsResponse },
                { typeof(PartialUpdateMarketingResultResponse), this.ProcessPartialUpdateMarketingResultResponse },
                { typeof(PartialUpdateMarketingResultsResponse), this.ProcessPartialUpdateMarketingResultsResponse },
                { typeof(SdkErrorResponse), this.ProcessSdkErrorResponse }
            };

            this.SetupClient(queueClientProvider, responseHandlerMapping);

            this.SampleMenuActions = new Dictionary<string, Tuple<string, Action>>
            {
                { "1", new Tuple<string, Action>("Retrieve a Marketing Result", this.RetrieveMarketingResult) },
                { "2", new Tuple<string, Action>("Create a Marketing Result", this.CreateMarketingResult) },
                { "3", new Tuple<string, Action>("Update a Marketing Result", this.UpdateMarketingResult) },
                { "4", new Tuple<string, Action>("Delete a Marketing Result", this.DeleteMarketingResult) },
                { "5", new Tuple<string, Action>("Retrieve a list of marketing result types", this.RetrieveMarketingResultTypes) },
                { "6", new Tuple<string, Action>("Retrieve multiple marketing results", this.RetrieveMarketingResults) },
                { "7", new Tuple<string, Action>("Create multiple Marketing Results", this.CreateMultipleMarketingResults) },
                { "8", new Tuple<string, Action>("Partially update a Marketing Result", this.PartiallyUpdateResult) },
                { "9", new Tuple<string, Action>("Partially update multiple Marketing Results", this.PartiallyUpdateMultipleResults) }
            };
        }

        /// <summary>
        /// Demonstrates RetrieveMarketingResultRequest and RetrieveMarketingResultResponse.
        /// </summary>
        private void RetrieveMarketingResult()
        {
            Console.WriteLine("This request retrieves a result.");
            Console.Write("Please type the ID (GUID) for the result to retrieve => ");
            Guid id;
            if (Guid.TryParse(Console.ReadLine(), out id))
            {
                var request = new RetrieveMarketingResultRequest { MarketingResultId = id };
                this.Client.ProcessRequest(request);
            }
            else
            {
                Console.WriteLine("Incorrect ID");
            }
        }

        /// <summary>
        /// Handles the RetrieveMarketingResultResponse that is received from the response queue. Displays the results.
        /// </summary>
        /// <param name="response">The RetrieveMarketingResultResponse received after sending a RetrieveMarketingResultRequest.</param>
        private void ProcessRetrieveMarketingResultResponse(SdkResponse response)
        {
            var retrieveResultResponse = (RetrieveMarketingResultResponse)response;
            Console.WriteLine("Processing RetrieveMarketingResultResponse.");

            if (this.updateRequestSent)
            {
                Console.WriteLine("Old actual for result: " + retrieveResultResponse.MarketingResult.ActualValue);
                Console.Write("Please type the new actual for the result => ");
                var actual = Console.ReadLine();
                double actualValue;
                if (!Double.TryParse(actual, out actualValue))
                {
                    Console.WriteLine("Incorrect Actual Value");
                    return;
                }

                Console.WriteLine("Old forecast for result: " + retrieveResultResponse.MarketingResult.ActualValue);
                Console.Write("Please type the new forecast for the result => ");
                var forecast = Console.ReadLine();
                double forecastValue;
                if (!Double.TryParse(forecast, out forecastValue))
                {
                    Console.WriteLine("Incorrect Forecast Value");
                    return;
                }

                var result = retrieveResultResponse.MarketingResult;
                result.ActualValue = actualValue;
                result.ForecastValue = forecastValue;
                var request = new CreateOrUpdateMarketingResultRequest { MarketingResult = result };
                this.Client.ProcessRequest(request);
            }
            else
            {
                this.PrintMarketingResult(retrieveResultResponse.MarketingResult);
            }
        }

        /// <summary>
        /// Print the content of a marketing result.
        /// </summary>
        /// <param name="result">The result to display.</param>
        private void PrintMarketingResult(MarketingResult result)
        {
            var belongsToCompanyId = result.BelongsToCompany == null ? string.Empty : result.BelongsToCompany.Id.ToString();
            var contactId = result.Contact == null ? string.Empty : result.Contact.Id.ToString();
            var emailId = result.EmailMessage == null ? string.Empty : result.EmailMessage.Id.ToString();
            var jobId = result.Job == null ? string.Empty : result.Job.Id.ToString();
            var eventId = result.Event == null ? string.Empty : result.Event.Id.ToString();
            var campaignId = result.Campaign == null ? string.Empty : result.Campaign.Id.ToString();
            var programId = result.Program == null ? string.Empty : result.Program.Id.ToString();
            var resultTypeId = result.Type == null ? string.Empty : result.Type.Id.ToString();
            var originOfChanges = result.OriginOfChanges == null ? string.Empty : string.Join(";", result.OriginOfChanges.Distinct());

            Console.WriteLine(
                @"
                ID: {0}
                Version: {1}
                Contact: {2}
                Belongs To Company ID: {3}
                Email Message: {4}
                Job: {5}
                Event: {6}
                Program: {7}
                Campaign: {8}
                Comment: {9}
                Type: {10}
                Actual Value: {11}
                ForeCast Value: {12}
                Date: {13}
                OriginOfChanges: {14}",
                result.Id,
                result.Version.ToString(CultureInfo.CurrentCulture),
                contactId,
                belongsToCompanyId,
                emailId,
                jobId,
                eventId,
                programId,
                campaignId,
                result.Comment,
                resultTypeId,
                result.ActualValue.ToString(CultureInfo.CurrentCulture),
                result.ForecastValue.ToString(CultureInfo.CurrentCulture),
                result.Date.ToString(CultureInfo.CurrentCulture),
                originOfChanges);
        }

        /// <summary>
        /// Demonstrates how to create a marketing result.
        /// </summary>
        private void CreateMarketingResult()
        {
            Console.WriteLine("This request creates a result.");
            var result = CreateMarketingResultModel();

            var request = new CreateOrUpdateMarketingResultRequest { MarketingResult = result };
            this.Client.ProcessRequest(request);
        }

        /// <summary>
        /// Demonstrate how to create multiple marketing results
        /// </summary>
        private void CreateMultipleMarketingResults()
        {
            Console.WriteLine("This request will create multiple marketing results.");
            Console.WriteLine("Enter values for the first result");
            var marketingResult1 = CreateMarketingResultModel();
            Console.WriteLine("Enter values for the second result");
            var marketingResult2 = CreateMarketingResultModel();

            if (marketingResult1 == null || marketingResult2 == null)
            {
                return;
            }

            var request = new CreateOrUpdateMarketingResultsRequest { MarketingResultRequests = new[] { marketingResult1, marketingResult2 } };
            this.Client.ProcessRequest(request);
        }

        /// <summary>
        /// Creates a <see cref="MarketingResult"/> entity
        /// </summary>
        /// <returns> Returns the <see cref="MarketingResult"/> entity </returns>
        private static MarketingResult CreateMarketingResultModel()
        {
            Console.Write("Please type the ID (GUID) for the result => ");
            var guid = Console.ReadLine();
            var id = TryParseGuid(guid);

            Console.Write("Please type the ID (GUID) for the company that the result belongs to => ");
            var companyGuid = Console.ReadLine();
            var belongsToCompanyId = TryParseGuid(companyGuid);

            Console.Write("Please type the ID (GUID) for the type of the result => ");
            var resultGuid = Console.ReadLine();
            var resultTypeId = TryParseGuid(resultGuid);

            return new MarketingResult
            {
                Id = id,
                BelongsToCompany = new Company { Id = belongsToCompanyId },
                Type = new MarketingResultType { Id = resultTypeId },
                Date = DateTime.UtcNow
            };
        }

        /// <summary>
        /// Demonstrates how to update a marketing result.
        /// </summary>
        private void UpdateMarketingResult()
        {
            Console.WriteLine("This request updates a result.");
            Console.Write("Please type the ID (GUID) for the result => ");
            Guid id;
            if (!Guid.TryParse(Console.ReadLine(), out id))
            {
                Console.WriteLine("Incorrect ID");
                return;
            }

            this.updateRequestSent = true;
            var request = new RetrieveMarketingResultRequest { MarketingResultId = id };
            this.Client.ProcessRequest(request);
        }

        /// <summary>
        /// Demonstrates how to partially update a marketing result
        /// </summary>
        private void PartiallyUpdateResult()
        {
            Console.WriteLine("This request partially updates a marketing result.");
            var partialRequestUpdateItem1 = CreatePartiallyUpdateResultItem();
            if (partialRequestUpdateItem1 == null)
            {
                return;
            }

            var partialUpdateResultRequest = new PartialUpdateMarketingResultRequest
            {
                PartialUpdateMarketingResultItem = partialRequestUpdateItem1
            };
            this.Client.ProcessRequest(partialUpdateResultRequest);
        }

        /// <summary>
        /// Demonstrates how to partially update multiple marketing results
        /// </summary>
        private void PartiallyUpdateMultipleResults()
        {
            Console.WriteLine("This request partially updates multiple marketing results.");
            Console.WriteLine("Enter values for the first update result item");
            var partialRequestUpdateItem1 = CreatePartiallyUpdateResultItem();
            Console.WriteLine("Enter values for the second update result item");

            var partialRequestUpdateItem2 = CreatePartiallyUpdateResultItem();
            if (partialRequestUpdateItem1 == null || partialRequestUpdateItem2 == null)
            {
                return;
            }

            var partialUpdateMultipleResultRequest = new PartialUpdateMarketingResultsRequest
            {
                PartialUpdateMarketingResultItems = new[]
                {
                    partialRequestUpdateItem1, partialRequestUpdateItem2
                }
            };
            this.Client.ProcessRequest(partialUpdateMultipleResultRequest);
        }

        /// <summary>
        /// Creates a <see cref="PartialUpdateMarketingResultItem"/> instance, used to hold the fields to be updated, 
        /// by a PartialUpdate request
        /// </summary>
        /// <returns> Returns the <see cref="PartialUpdateMarketingResultItem"/> instance </returns>
        private static PartialUpdateMarketingResultItem CreatePartiallyUpdateResultItem()
        {
            PartialUpdateMarketingResultItem partialUpdateMarketingResultItem;
            Console.Write("Please type the ID (GUID) for the Result => ");
            Guid id;
            if (!Guid.TryParse(Console.ReadLine(), out id))
            {
                Console.WriteLine("Incorrect ID");
                partialUpdateMarketingResultItem = null;
            }
            else
            {
                partialUpdateMarketingResultItem = new PartialUpdateMarketingResultItem
                {
                    Id = id,
                    MarketingResultFields = new Dictionary<MarketingResultFields, object>()
                };

                // Get all the fields of the MarketingResult entity
                var marketingResultFieldsStartKey = 1;
                var fields = Enum.GetValues(typeof(MarketingResultFields)).Cast<MarketingResultFields>()
                    .ToDictionary(resultField => marketingResultFieldsStartKey++);
                foreach (var field in fields)
                {
                    Console.WriteLine("{0}\t{1}", field.Key, field.Value);
                }

                // Get the strategies used to update each field
                var setValuesStrategiesForResult = GetSetValuesStrategiesForResult();

                // Select all the fields that will be updated and set their values
                while (true)
                {
                    Console.WriteLine("Select value to change:");
                    var selection = Console.ReadLine();
                    if (selection == string.Empty)
                    {
                        break;
                    }

                    int intSelection;
                    if (int.TryParse(selection, out intSelection) && fields.ContainsKey(intSelection))
                    {
                        var selectedField = fields[intSelection];
                        Console.WriteLine("Input new value for {0}:", selectedField);

                        // Set the value for the field that will be updated
                        var input = Console.ReadLine();
                        var value = setValuesStrategiesForResult[selectedField].Invoke(input);
                        partialUpdateMarketingResultItem.MarketingResultFields[selectedField] = value;
                    }
                }
            }

            return partialUpdateMarketingResultItem;
        }

        /// <summary>
        /// Handles the <see cref="CreateOrUpdateMarketingResultResponse"/> that is received from the response queue. Displays the marketing result.
        /// </summary>
        /// <param name="response">The <see cref="CreateOrUpdateMarketingResultResponse"/> received after sending a <see cref="CreateOrUpdateMarketingResultRequest"/>.</param>
        private void ProcessCreateOrUpdateMarketingResultResponse(SdkResponse response)
        {
            var createOrUpdateResultResponse = (CreateOrUpdateMarketingResultResponse)response;
            Console.WriteLine("Processing CreateOrUpdateResultResponse.");

            if (!createOrUpdateResultResponse.Succeeded)
            {
                Console.WriteLine("Failed to create/update result");
                return;
            }

            Console.WriteLine("The create/update result");
            this.PrintMarketingResult(createOrUpdateResultResponse.MarketingResult);
            this.updateRequestSent = false;
        }

        /// <summary>
        /// Handles the <see cref="CreateOrUpdateMarketingResultsResponse"/> that is received from the response queue.
        /// Displays the results of this request
        /// </summary>
        /// <param name="response">The <see cref="CreateOrUpdateMarketingResultsResponse"/> received after sending a <see cref="CreateOrUpdateMarketingResultsRequest"/>.</param>
        private void ProcessCreateOrUpdateMarketingResultsResponse(SdkResponse response)
        {
            var createOrUpdateMultipleResultResponse = (CreateOrUpdateMarketingResultsResponse)response;
            Console.WriteLine("Processing CreateOrUpdateResultResponse.");
            Console.WriteLine(createOrUpdateMultipleResultResponse.Message);

            foreach (var reply in createOrUpdateMultipleResultResponse.MarketingResultResponses)
            {
                Console.WriteLine(
                    "ID: {0}, Success: {1}, Message: {2}",
                    reply.MarketingResultGuid,
                    reply.Succeeded, 
                    reply.Message);
            }
        }

        /// <summary>
        /// Handles the <see cref="PartialMarketingResultUpdateResponse"/> that is received from the response queue.
        /// </summary>
        /// <param name="response">The <see cref="PartialMarketingResultUpdateResponse"/> received after sending a <see cref="PartialMarketingResultUpdateRequest"/>.</param>
        private void ProcessPartialUpdateMarketingResultResponse(SdkResponse response)
        {
            var partialMarketingUpdateResponse = (PartialUpdateMarketingResultResponse)response;
            Console.WriteLine("Processing PartialMarketingResultUpdateResponse");
            Console.WriteLine(
                "ID: {0}, Success: {1}, Message: {2}",
                partialMarketingUpdateResponse.Id,
                partialMarketingUpdateResponse.Succeeded,
                partialMarketingUpdateResponse.Message);
        }

        /// <summary>
        /// Handles the <see cref="PartialUpdateMarketingResultsResponse"/> that is received from the response queue.
        /// </summary>
        /// <param name="response">The <see cref="PartialUpdateMarketingResultsResponse"/> received after sending a <see cref="PartialUpdateMarketingResultsRequest"/>.</param>
        private void ProcessPartialUpdateMarketingResultsResponse(SdkResponse response)
        {
            var createOrUpdateMultipleResultResponse = (PartialUpdateMarketingResultsResponse)response;
            Console.WriteLine("Processing PartialMultipleMarketingResultsUpdateResponse.");
            Console.WriteLine(createOrUpdateMultipleResultResponse.Message);

            foreach (var reply in createOrUpdateMultipleResultResponse.PartialUpdateMarketingResultResponses)
            {
                Console.WriteLine("ID: {0}, Success: {1}, Message: {2}", reply.Id, reply.Succeeded, reply.Message);
            }
        }

        /// <summary>
        /// Demonstrates how to delete a marketing result.
        /// </summary>
        private void DeleteMarketingResult()
        {
            Console.WriteLine("This request deletes a result.");
            Console.Write("Please type the ID (GUID) for the result => ");
            Guid id;
            if (!Guid.TryParse(Console.ReadLine(), out id))
            {
                Console.WriteLine("Incorrect ID");
                return;
            }

            var request = new DeleteMarketingResultRequest { MarketingResultId = id };
            this.Client.ProcessRequest(request);
        }

        /// <summary>
        /// Handles the DeleteMarketingResultResponse that is received from the response queue.
        /// </summary>
        /// <param name="response">The DeleteResultMarketingResponse received after sending a DeleteMarketingResultRequest.</param>
        private void ProcessDeleteMarketingResultResponse(SdkResponse response)
        {
            var deleteResultResponse = (DeleteMarketingResultResponse)response;
            Console.WriteLine("Processing DeleteMarketingResultResponse.");

            Console.WriteLine(deleteResultResponse.Succeeded ? "Result deleted" : "Failed to delete result");
        }

        /// <summary>
        /// Demonstrates how to retrieve marketing result types.
        /// </summary>
        private void RetrieveMarketingResultTypes()
        {
            Console.WriteLine("This request retrieves a list of result types.");
            var request = new RetrieveMarketingResultTypesRequest();
            this.Client.ProcessRequest(request);
        }

        /// <summary>
        /// Handles the RetrieveMarketingResultTypesResponse that is received from the response queue.
        /// </summary>
        /// <param name="response">The RetrieveMarketingResultTypesResponse received after sending a RetrieveMarketingResultTypesRequest.</param>
        private void ProcessRetrieveMarketingResultTypesResponse(SdkResponse response)
        {
            var retrieveResultTypesResponse = (RetrieveMarketingResultTypesResponse)response;
            Console.WriteLine("Processing RetrieveResultTypesResponse.");

            if (retrieveResultTypesResponse.Succeeded)
            {
                Console.WriteLine("List of result types");
                Console.WriteLine("ID\t\t\t\t\tName");
                foreach (var status in retrieveResultTypesResponse.MarketingResultTypes)
                {
                    Console.WriteLine(status.Id + "\t" + status.Name);
                }
            }
            else
            {
                Console.WriteLine("Failed to retrieve result types");
            }
        }

        /// <summary>
        /// Demonstrates how to retrieve multiple marketing results.
        /// </summary>
        private void RetrieveMarketingResults()
        {
            Console.WriteLine("This request will retrieve multiple results.");
            Console.Write("Filter on Origin of changes =>");
            var originOfChange = Console.ReadLine();

            var request = new RetrieveMarketingResultsRequest { MaxNumberOfRecordsToGet = 100, OriginOfChange = originOfChange };
            this.Client.ProcessRequest(request);
        }

        /// <summary>
        /// Handles the RetrieveMarketingResultsResponse that is received from the response queue. Displays the marketing results.
        /// </summary>
        /// <param name="response">The RetrieveMarketingResultsResponse received after sending a RetrieveMarketingResultsRequest.</param>
        private void ProcessRetrieveMarketingResultsResponse(SdkResponse response)
        {
            var retrieveResultsResponse = (RetrieveMarketingResultsResponse)response;
            Console.WriteLine("Processing RetrieveResultsResponse.");

            var counter = 1;
            foreach (var result in retrieveResultsResponse.MarketingResults)
            {
                Console.WriteLine("\nResult #{0}", counter++);
                this.PrintMarketingResult(result);
            }
        }

        /// <summary>
        /// Handles the <see cref="SdkErrorResponse"/> received from the response queue. Displays the error message.
        /// </summary>
        /// <param name="response">The <see cref="SdkErrorResponse"/> received after sending an <see cref="SdkRequest"/>.</param>
        private void ProcessSdkErrorResponse(SdkResponse response)
        {
            var sdkErrorResponse = (SdkErrorResponse)response;
            Console.WriteLine("An SdkErrorResponse was received.");
            Console.WriteLine("Error message: {0}", sdkErrorResponse.Message);
        }

        /// <summary>
        /// Casts safely, a string value to a GUID
        /// </summary>
        /// <param name="input">The date to be cast to GUID</param>
        /// <returns>The GUID representation of the input</returns>
        private static Guid TryParseGuid(string input)
        {
            Guid guid;
            if (!Guid.TryParse(input, out guid))
            {
                Console.WriteLine("Incorrect ID");
            }

            return guid;
        }

        /// <summary>
        /// Casts safely, a string value to double
        /// </summary>
        /// <param name="input">The date to be cast to double</param>
        /// <returns>The double representation of the input</returns>
        private static object TryParseDouble(string input)
        {
            double actualValue;
            var isParsedSuccessfuly = double.TryParse(input, out actualValue);
            if (!isParsedSuccessfuly)
            {
                Console.WriteLine("Incorrect input value, cannot be parsed to number. Please re-enter the new value of the same field.");
            }
            return actualValue;
        }

        /// <summary>
        /// Gets the strategies used to set the values for each field
        /// </summary>
        /// <returns>Returns a dictionary with the field name as a key and the strategy to set it as value</returns>
        private static IDictionary<MarketingResultFields, Func<string, object>> GetSetValuesStrategiesForResult()
        {
            return new Dictionary<MarketingResultFields, Func<string, object>>
            {
                { MarketingResultFields.BelongsToCompany, input => new Company { Id = TryParseGuid(input) } },
                { MarketingResultFields.Contact, input => new Contact { Id = TryParseGuid(input) } },
                { MarketingResultFields.Campaign, input => new Campaign { Id = TryParseGuid(input) } },
                { MarketingResultFields.Comment, input => input },
                { MarketingResultFields.EmailMessage, input => new EmailMessage { Id = TryParseGuid(input) } },
                { MarketingResultFields.Event, input => new Event { Id = TryParseGuid(input) } },
                { MarketingResultFields.Job, input => new Job { Id = TryParseGuid(input) } },
                { MarketingResultFields.Program, input => new Program { Id = TryParseGuid(input) } },
                { MarketingResultFields.Type, input => new MarketingResultType { Id = TryParseGuid(input) } },
                { MarketingResultFields.ActualValue, TryParseDouble },
                { MarketingResultFields.ForecastValue, TryParseDouble },
                { MarketingResultFields.OriginOfChanges, input => new Collection<string> { input } }
            };
        }
    }
}

Troubleshooting

  • If the response isn’t received in time, you’ll get the following error message:

    “The request has been sent but the response was not received. You may want to wait a few more seconds and try to receive the response again or try increasing the ResponseMessageTimeout in client.cs. “

    Some of the possible reasons why the response wasn’t received:

    • The server took longer than expected to process this response. Try selecting Option A, to see the response. If this issue occurs frequently, consider changing the value of the ResponseMessageTimeout constant in your client.cs file.

    • Either your client is looking at the wrong response queue, or Microsoft Dynamics Marketing is unable to write to the response queue due to a configuration error. To learn how to set up your queues correctly, see Getting started with the SDK.

  • If you don’t receive a response immediately, try using the Get all responses for this session option. Sometimes a response may take longer than the default time-out period.

  • If you never receive the response, make sure your request and response queue names and namespace match the details you provided on Home > Settings > Administrator > Integration Options. More information: Site configuration and integration settings.

See Also

Microsoft.Dynamics.Marketing.SDK.Common
Microsoft.Dynamics.Marketing.SDK.Messages
Microsoft.Dynamics.Marketing.SDK.Messages.MarketingResult
Microsoft.Dynamics.Marketing.SDK.Model
Developer overview of Microsoft Dynamics Marketing
Gain insights using email marketing results
Getting started with the SDK
Quick start with sample code
Sample code
Assembly included in the Microsoft Dynamics Marketing SDK
Programming reference for Microsoft Dynamics Marketing