Using WCF REST Starter Kit to Access Constant Contact API

Problem: Allow customers to sign up for email newsletters and synchronize those accounts with Constant Contact.

Constant Contact is a company that provides Email Marketing services. You can use their editor to create nice looking emails and then configure a list of contacts. Constant Contact handles all the email sending, bounces, and unsubscribe activities. They also provide excellent reporting features to track how many people actually view your emails or click on the contained links.

The nice folks at Constant Contact provide a set of web services for accessing account data. These interfaces are implemented as REST services utilizing the Atom Publication Protocol (AtomPub) and Atom Syndication Format. At first it might seem odd to be accessing data objects via a blogging protocol but it actually works quite naturally. So well that Google’s GData and Microsoft’s ADO.NET Data Services also support this technique.

Writing all the HTTP, Auth, and XML parsing code can be a real drag. Luckily Microsoft is releasing a WCF REST Starter Kit. From the CodePlex summary:

The WCF REST Starter Kit is a set of .Net Framework classes and Visual Studio features and templates that enable users to create and access REST-style Windows Communication Foundation (WCF) services. These services are based on the WCF web programming model available in .Net 3.5 SP1. The starter kit also contains the full source code for all features, detailed code samples, and unit tests.

This starter kit makes accessing the Constant Contact API quite simple. Call GetEntry or GetFeed with a URI and get back a SyndicationItem or SyndicationFeed (collection of items). Similar methods exist for adding and updating data (AddEntry and UpdateEntry).

The following is one method from my ContactListProvider class:

public ContactList GetContactList(string id)
{
   AtomPubClient client = new AtomPubClient();
   client.TransportSettings.Credentials = GetLoginCredentials();

   // Place in a try block to ensure that any errors are caught
   try
   {
      SyndicationItem item = client.GetEntry(new Uri(id));

      ContactList list = new ContactList(item.Content as XmlSyndicationContent);

      return list;
   }
   catch (WebException ex)
   {
      _log.Error("WebException: " + ex.Status + " " + ex.Message, ex);
      return null;
   }
   catch (Exception ex)
   {
      // Get the exception type
      _log.Error("Exception: " + ex.Message, ex);
      return null;
   }
}

Contact me via comments if you want a copy of all the providers.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • StumbleUpon
  • TwitThis

5 Responses to “Using WCF REST Starter Kit to Access Constant Contact API”

  1. Dave B Says:

    Hi James,

    This link was recently sent to me to take a look at. Your code looks very clean, I’m really interested to see how you applied the new Syndication classes to your library. I’m one of the Constant Contact developers who supports our Web Services group.

    If you can send over the code, I’d really love to check it out. Also, have you thought of posting a link to this blog in our developer forums for people to come here? We get lots of requests for code samples that would benefit from coming here.

  2. Jason N Says:

    Hi James,

    I am very interested in receiving the providers. I’m working on a project for our marketing department and your code would be very beneficial to this.

    Cheers,
    Jason

  3. james Says:

    I’ll clean up the code a tad and put together a simple sample application. Look for it soon.

  4. WCF REST Starter Kit to Constant Contact Starter Kit at freemind blogs Says:

    [...] details on how I used the WCF REST Starter Kit to integrate with the Constant Contact AtomPub API (posted here). It’s shamefully simple but here it is. If you are not satisfied I will give you your money [...]

  5. james Says:

    Updated code here: http://blogs.freemind.net/index.php/wcf-rest-starter-kit-to-constant-contact-sample-application/73/

Leave a Reply