TRUVEO XML API & WCF: Parsing Video Data

When interfacing with external application I like to hide the remote system behind a proxy class.
Visual Studio will generate a proxy when you add a webreference, but when using the TRUVEO XML API we need to
manually code the proxy.
An important part of the proxy is the data structures which are passed as part of the API.
The most significant data object when searching for videos is... the video structure.

Extending the previous TRUVEO samples I've blogged about, I've now mapped the video structure using Windows Communication Foundation tags.

A couple of significant things became apparent when doing this.

Windows Communication Foundation, by default, expects the XML tags be sorted alphabetically.
Since this is not the case for the XML returned by the TRUVEO search we need to solve this by adding the 'Order' parameter to the DataMemberAttribute.
This makes the attribute declaration look like:

/// 
/// A string that contains the language associated with the video in this result. 
/// For example, this field might contain a value such as 'English', 'French', etc.. 
/// Generally, language names will correspond with the ISO 639 specification. 
/// 
[DataMember(Name = "language", Order = 30)]
public string Language { get; set; }

The second thing I ran into is that dates are passed as strings and these strings do not adhere to the standardized format for XML dates.

I found dates like "Sun. Sept. 9 2007" ,"2006-9-15" and "Fri, 07 Sep 2007 20:04:41 -0400". Pretty wild variations.
To solve this I've mapped the XML field onto a private property, allowing me to implement some custom parsing of the XML value before
assigning it to my public property.

/// 
/// Private property for parsing the date produced to a .NET DateTime 
/// represention.
/// 
[DataMember(Name = "dateProduced", Order = 31)]
private string parseDateProduced
{
    get
    {
        return DateProduced.ToString();
    }
    set
    {
        try
        {
            // This catches most conversion errors
            DateProduced = Convert.ToDateTime(value);
        }
        catch ()
        {
            //TODO: implement more advanced parsing
        }
    }
}
/// 
/// A string that describes the date or time period when the video in 
/// this result was originally produced. 
/// 
public DateTime DateProduced { get; set; }

The complete code for the Video datastructure can be downloaded here (cs, zip).

- Mark Blomsma

.NET 3.5

After receiving an e-mail today I'd just like to clarify. The code in this blog entry is based on Windows Communication Foundation in .NET 3.5.

- Mark Blomsma