TRUVEO - Build your own search page using ASP.NET, WCF and C#
After my sample from two weeks ago I wanted to use what I had build before and build an ASP.NET webpage which performs a search and lists the results as hyperlinks.
First I isolated the code which performs the actual search into a library.
namespace DevelopOne.Truveo
{
public static class TruveoService
{
public static Video[] Search(string query)
{
WebHttpBinding webBinding = new WebHttpBinding();
ChannelFactory factory = new ChannelFactory(webBinding, new EndpointAddress("http://xml.searchvideo.com/apiv3"));
factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
IAolVideoSearchService proxy = factory.CreateChannel();
Response returnValue = proxy.Search("1x1jhj64466mi12ia", "truveo.videos.getVideos", query);
return returnValue.VideoSet;
}
}
}
Next I created an ASP.NET project, add a textbox for entering my search query and add an ObjectDataSource to the page. I make the ObjectDataSource point to TruveoService.Search method and take the value of the textbox as a parameters. Next I add a GridView control and bind it to the ObjectDataSource.
The resulting ASP.NET page is simple, elegant and effective.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<p style="text-align:center">Search:
<asp:DataList ID="DataList1" runat="server" DataSourceID="ObjectDataSource1">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("Url") %>'
Text='<%# Eval("Title") %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:DataList>
</p>
<p style="text-align:center">
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="Search" TypeName="DevelopOne.Truveo.TruveoService">
<SelectParameters>
<asp:controlparameter ControlID="TextBox1" Name="query" PropertyName="Text"
Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
</form>
</body>
</html>
Without hardly any code we have our very own search engine page!
» Submitted by markdeveloper on September 5, 2007 - 9:40pm.
- markdeveloper's blog
- Login or register to post comments
- Subscribe
