//THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
//TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//PARTICULAR PURPOSE.
//
//Copyright (C) 2007 Microsoft Corporation. All rights reserved.
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services.Protocols;
using System.Net;
using ConsoleSampleWebSearch.LiveSearch;
namespace ConsoleSampleWebSearch
{
class Program
{
static void Main(string[] args)
{
/* TIP: To run any of the samples featured in the API Reference, remove the code in the try...catch
* block and replace it with the code from the example topic you want to run. */
try
{
MSNSearchService s = new MSNSearchService();
SearchRequest searchRequest = new SearchRequest();
int arraySize = 1;
SourceRequest[] sr = new SourceRequest[arraySize];
sr[0] = new SourceRequest();
sr[0].Source = SourceType.Web;
searchRequest.Query = "live search";
searchRequest.Requests = sr;
// Enter the Application ID, in double quotation marks, supplied by the
// Developer Provisioning System, as the value of the AppID on the SearchRequest.
searchRequest.AppID = "YOUR_APP_ID_GOES_HERE";
searchRequest.CultureInfo = "en-US";
SearchResponse searchResponse;
searchResponse = s.Search(searchRequest);
foreach (SourceResponse sourceResponse in searchResponse.Responses)
{
Result[] sourceResults = sourceResponse.Results;
if (sourceResponse.Total > 0)
{
Console.WriteLine(sourceResponse.Source.ToString() + " - Total Results: " + sourceResponse.Total.ToString());
Console.WriteLine();
}
foreach (Result sourceResult in sourceResults)
{
if ((sourceResult.Title != null) && (sourceResult.Title != String.Empty))
Console.WriteLine("Title: " + sourceResult.Title);
if ((sourceResult.Description != null) && (sourceResult.Description != String.Empty))
Console.WriteLine("Description: " + sourceResult.Description);
if ((sourceResult.Url != null) && (sourceResult.Url != String.Empty))
Console.WriteLine("URL: " + sourceResult.Url);
Console.WriteLine("*****************************************************");
}
}
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
catch (System.Web.Services.Protocols.SoapException fault)
{
Console.WriteLine(fault.Detail.InnerText.ToString());
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
catch (System.Net.WebException webx)
{
Console.WriteLine(webx.ToString());
}
/* This is the end of the try...catch block. */
}
}
}