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.
