1

Creating a Triggered Send call, which works fine until I try to enumerate a Dictionary to set the Subscriber Attributes (see comment on line where exception occurs). At this point, both the "properties" Dictionary (full of data), and the Subscriber.Attribute[] have a count of 22 (as expected). My expectation is that each Attribute.Name be set to the Dictionary.Key and Attribute.Value be set to the Dictionary.Value (at the current index).

Initially, I thought it may be an issue with the names of the properties not matching the names of the attributes in the TSDE, but it's not even getting that far.

I can't seem to see where the problem is occurring -- can YOU see the problem?

public void TriggeredSendEmailAll(string subKey, string subEmail, Dictionary<string,string> properties)
    {
        //CREATE BINDINGS
        BasicHttpBinding binding = new BasicHttpBinding()
        {
            Name = "sfmcBinding",
            ReceiveTimeout = new TimeSpan(0, 5, 0),
            OpenTimeout = new TimeSpan(0, 5, 0),
            CloseTimeout = new TimeSpan(0, 5, 0),
            SendTimeout = new TimeSpan(0, 5, 0)
        };
        binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
        binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

        //INSTANTIATE SOAP CLIENT
        Configuration cfg = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming);
        ServiceModelSectionGroup smsg = ServiceModelSectionGroup.GetSectionGroup(cfg);
        ClientSection cs = smsg.Client;
        SoapClient client = new SoapClient(binding, new EndpointAddress(cs.Endpoints[0].Address));
        client.ClientCredentials.UserName.UserName = sfmcUsername;
        client.ClientCredentials.UserName.Password = sfmcPassword;

        TriggeredSendDefinition tsDef = new TriggeredSendDefinition()
        {
            CustomerKey = sfmcTriggeredSendDef
        };

        Subscriber sub = new Subscriber()
        {
            EmailAddress = subEmail,
            SubscriberKey = subKey
        };
        sub.Attributes = new libNotificationServices.SFMC.Attribute[properties.Count];

        //ENUMERATE PROPERTIES TO ATTRIBUTES
        int i = 0;
        foreach (KeyValuePair<string,string> prop in properties)
        {
            sub.Attributes[i].Name = prop.Key;  //****THIS IS WHERE THE EXCEPTION OCCURS****//
            sub.Attributes[i].Value = prop.Value;
            i++;
        }

        TriggeredSend ts = new TriggeredSend()
        {
            TriggeredSendDefinition = tsDef,
            Subscribers = new Subscriber[] { sub }
        };

        APIObject[] sends = { ts };

        CreateOptions tsOpts = new CreateOptions()
        {
            RequestType = RequestType.Asynchronous
        };

        CreateResult[] results = client.Create(tsOpts, sends, out string requestID, out string overallStatus);

        //DEBUG THIS CRAP
        Console.WriteLine("request: {0} | status: {1}", requestID, overallStatus);
        Console.Read();
    }
2
  • @jbeckom--> this question not related to marketing cloud
    – Ravi.A
    May 31, 2019 at 6:42
  • @pkharries - this is SFMC related - it is the SDK to perform a TSD. May 31, 2019 at 12:01

1 Answer 1

1

I knew I was missing something minor -- I needed to add a new Attribute() for each property... hopefully this can help someone else...

//ENUMERATE PROPERTIES TO ATTRIBUTES
int i = 0;
foreach (KeyValuePair<string,string> prop in properties)
{
   sub.Attributes[i]  = new libNotificationServices.SFMC.Attribute()
   {
      Name = prop.Key,
      Value = prop.Value
   };
   i++;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .