1. Download GoogleSearch.wsdl
2. Open .NET "SDK Command Window"
3. Convert .wsdl to corresponding .cs class
wsdl GoogleSearch.wsdl
4. Start a new Project.
5. Add GoogleSearch.cs to the project.
6. Add reference to System.Web.Services to the project.
7. C# code :
try
{
String googleKey = "PUT YOUR KEY HERE";
GoogleSearchService objGoogle = new GoogleSearchService();
GoogleSearchResult objGoogRes;
objGoogRes = objGoogle.doGoogleSearch(googleKey, "Jaguar", 0, 5, true, "", true, "en", "","");
//CALL THE GOOGLE SEARCH WEB SERVICE
//objGoogRes = objGoogle.doGoogleSearch("LICENSE KEY", this.textBox1.Text, 0, 5, true, "", true, "en", "", "");
for (int i = 0; i < 5; i++)
{
Console.WriteLine("URL : " + objGoogRes.resultElements[i].URL);
Console.WriteLine("Title : " + objGoogRes.resultElements[i].title);
Console.WriteLine("Summary : " + objGoogRes.resultElements[i].summary);
Console.WriteLine("Snippet : " + objGoogRes.resultElements[i].snippet); }
}
catch (Exception ex)
{
Console.WriteLine("Exception Raised: " + ex.Message);
}
finally
{
}
doGoogleSearch Parameters
- key - Your Google API key, which you received when you signed up for Google web services.
- q - The search word or phrase you're looking for. The syntax is exactly the same as Google's web form, so if you know any advanced search syntax or tricks, they all work here as well.
- start - The index of the result to start on. Like the interactive web version of Google, this function returns 10 results at a time. If you wanted to get the second “page” of results, you would set start to 10.
- maxResults - The number of results to return. Currently capped at 10, although you can specify fewer if you are only interested in a few results and want to save a little bandwidth.
- filter - If True, Google will filter out duplicate pages from the results.
- restrict - Set this to country plus a country code to get results only from a particular country. Example: countryUK to search pages in the United Kingdom. You can also specify linux, mac, or bsd to search a Google-defined set of technical sites, or unclesam to search sites about the United States government.
- safeSearch - If True, Google will filter out porn sites.
- lr (“language restrict”) - Set this to a language code to get results only in a particular language.
- ie and oe (“input encoding” and “output encoding”) - Deprecated, both must be utf-8.