The last couple of weeks I've been building up little bits (setting up a WCF channel, ASP.NET integration, parsing video data) of sample code allowing you to use Windows Communication Foundation 3.5 to integrate TRUVEO into a .NET application. Since most bits have been covered it's now time to pull it together into an ASP.NET application and build our own custom TRUVEO search page.
The image below shows the sample application in action.
Notice that we're using the thumbnails as an index for selecting the video you want to see. Cool right? When you hover your mouse over an image the title of the video is shown as a tooltip.
The complete source (Visual Studio 2008 solution) for this sample (zip) can be found here.
A couple of points of interest when looking at the code for this sample.
An explicit search button has been added in order to avoid unnecessary roundtrips to the search service.
This also means that I'm not using an ObjectDataSource anymore, but rather retrieve the data, custom databind the data and put the search results into viewstate.
In order to be able to store the Video array into Viewstate I had to mark the class as Serializable.
Below, handling the button click of the search button.
///
/// Handle Search button click.
///
/// Perform search and store results in SearchResults.
/// Then bind the results to the datalist.
/// Lastly update the details at the top of the page.
///
protected void btnSearch_Click(object sender, EventArgs e)
{
SearchResults = TruveoService.Search(this.txtSearch.Text);
this.ListResults.DataSource = SearchResults;
this.ListResults.SelectedIndex = 0;
this.ListResults.DataBind();
SetDetails();
}
Below, when storing data in ViewState (or Session) I like to create a type property to do the mapping to and from viewState.
private Video[] _searchResults;
///
/// Private property mapping the SearchResults to viewstate.
///
/// In order for this to work the Video class had to be marked as
/// serializable.
///
private Video[] SearchResults
{
get
{
// deserialization is 'expensive', only do it once per request
if (_searchResults == null)
{
_searchResults = (Video[])this.ViewState["SearchResults"];
}
return _searchResults;
}
set
{
this.ViewState["SearchResults"] = value;
}
}
Below, the code showing the Serializable attribute on the Video class.
///
/// Video is defined within the 'http://xml.searchvideo.com' namespace.
/// In this sample we only define a video as having a title.
///
/// Video is marked as Serializable, allowing it to be serialized to XML,
/// enabling the class to be serialized to ViewState.
///
[Serializable]
[DataContract(Namespace = "http://xml.searchvideo.com")]
public class Video
{
//...
}
Ofcourse the sample application can still be improved in terms of look and feel. Let me know if you make any improvements :-)
- Mark Blomsma

Works great! but...
I seem to have a problem adding request parameters, such as "results" or "start". I tried to simply concatenate "&results=30" to the end of the search term before I pass the term to the TruveoService.Search() method. However, I always receive zero videos (I always receive several videos without doing the concatenation). Any ideas? I'm sure it's something I'm forgetting to do...Thank you in advance.