SearchServiceClient.Search Method

 

Performs a search based on a given query and options.


public SearchResponse Search(SearchRequest request)

request

A SearchRequest object that contains the header and parameter information for the service operation. Required.

Returns a SearchResponse Class, which contains a SearchResultSet Class array.

Example

private void MakeSearchRequest() {
	string Results = "";
	try {
		//  Set a Bing Maps key before making a request 
		string key = "Bing Maps Key";
		SearchService.SearchRequest searchRequest = new SearchService.SearchRequest();
		//  Set the credentials using a valid Bing Maps key 
		searchRequest.Credentials = new SearchService.Credentials();
		searchRequest.Credentials.ApplicationId = key;
		//  Set the search query and filter options 
		searchRequest.Query = "restaurant in Seattle, WA";
		searchRequest.SearchOptions = new SearchService.SearchOptions();
		searchRequest.SearchOptions.Filters = new SearchService.FilterExpression() {
			PropertyId = 3, CompareOperator = SearchService.CompareOperator.GreaterThanOrEquals, FilterValue = 8
		};
		//  Make the search request 
		SearchService.SearchServiceClient searchService = new SearchService.SearchServiceClient("BasicHttpBinding_ISearchService");
		SearchService.SearchResponse searchResponse = searchService.Search(searchRequest);
		string resultList = "";
		for (int i = 0; i < searchResponse.ResultSets[0].Results.Length; i++) {
			resultList = resultList + searchResponse.ResultSets[0].Results[i].Name + "\n";
		}
		Results = resultList;
	} catch (Exception ex) {
		Results = "An exception occurred: " + ex.Message;
	}
}
Show: