Building A Visual Search Service For IE8 With WCF - Part III

It's definitely about time to publish the promised third part of this series. This time I will cover the class model which I used to let the .Net XmlSerializer generate the necessary XML structure. I want to utilize almost the full breadth of the capabilities the Visual Search component is offering with respect of information display. So in this case the features are:

  • Categories or sections
  • Descriptions/Abstracts
  • Urls
  • Images

So the XML structure needs to look like the following:

<SearchSuggestion version="2.0" xmlns="" >
<Separator title=""/>
<Image source="" alt="" width="" height=""/>
<Separator title="Videos on metacafe"/>

As I already mentioned I'm using the XmlSerializer in the .Net framework to serialize the XML drafted above. XmlSerializer serializes objects into XML and probably most of the sources (responses from the video services APIs) are XML you might want to ask the question why doing the indirection via a .net object model and not simply use XML transformation with an XML Stylesheet and send it straight over the wire using an XmlWriter. This is a valid question and the main reason why I didn't do it that way is because I started off with the YouTube service which gave me a pretty nice .Net based client API and others probably will follow. Another reason is that I wanted to use WCF which gives you more flexibility in targetting other clients as well and some quality of service features and knobs to fine tune the service.

So the object model looks like outlined in the following class diagram.


The properties in the classes are all annotated with the necessary XmlSerializer Attributes. So for example the code for the SearchItem class looks like the following:

[XmlRootAttribute(Namespace = ""
, ElementName="SearchSuggestion")]
public class SearchItem {
public string version { get; set; }
[XmlElement(ElementName = "Query")]
public string query { get; set; }

[XmlArrayItem(ElementName="Separator", Type=typeof(Separator))]
[XmlArrayItem(ElementName="Item", Type=typeof(SectionItem))]
public object[] Section { get; set; }

The most important thing to mention here is that you need to define an array of type object in order to create the child elements of the section element as it needs to take two different types of objects (SectionItem and Separator). Another thing to mention is that the Section property is the aggregation of all results of the integrated video services and therefore I created a helper object (Section class). Every SearchController gets an instance of such a helper object to populate it with its own items and separator. In the end all helper objects of type Section are merged together to populate the SectionItem.Section property.

SearchItem sI = new SearchItem();

Section youTubeSection = new Section();

Section metacafeSection = new Section();







youTubeSection.items.CopyTo(mergedSection, 0);
metacafeSection.items.CopyTo(mergedSection, youTubeSection.items.Length);


sI.Section = mergedSection;

The rest of the model is quite straight forward and I think it needs no further illustration. I will publish the complete code of the Video Visual Search with the last part of this series anyway.

The next part which hopefully doesn't take as long to publish as this one will deal with the Search Interface and the concrete implementations of it. Here's as usual a little teaser.



DeliciousBookmark this on Delicious Share