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:
{
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.

May 20th, 2009 at 7:58 am
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.
May 21st, 2009 at 1:47 pm
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
May 22nd, 2009 at 11:02 am
I’ll clean up the code a tad and put together a simple sample application. Look for it soon.
May 22nd, 2009 at 11:23 am
[...] 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 [...]
May 22nd, 2009 at 11:28 am
Updated code here: http://blogs.freemind.net/index.php/wcf-rest-starter-kit-to-constant-contact-sample-application/73/