asp.net建立引用步骤。1.到google取得license,填入下面第一个参数(象乱码的地方);GoogleSearchResult b = a.doGoogleSearch("eD2A9vlQFHLGnNPZPOLJfQQhOsqYg+Mh",this.Txt.Text,PageNumber*10,10,false,"",false,this.DplLang.SelectedItem.Value,"UTF-8","UTF-8");2.将google的web service引入到web form工程;3.利用wsdl.exe生成web服务相关类文件,添加到web form工程;4.在web form上添加如下控件;protected System.Web.UI.WebControls.TextBox Txt;
protected System.Web.UI.WebControls.Button CmdSearch;
protected System.Web.UI.WebControls.Table TabResult;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.LinkButton LinkButton2;
protected System.Web.UI.WebControls.DropDownList DplLang;
protected System.Web.UI.WebControls.Label Label1;5.copy以下代码到****.aspx.cs中,运行就可以了。
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace MySearch
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox Txt;
protected System.Web.UI.WebControls.Button CmdSearch;
protected System.Web.UI.WebControls.Table TabResult;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.LinkButton LinkButton2;
protected System.Web.UI.WebControls.DropDownList DplLang;
protected System.Web.UI.WebControls.Label Label1; private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here if (this.IsPostBack)
{
this.LoadToTable(Int32.Parse(this.Label1.Text));
}
else
{
this.Label1.Text = "0";
}
} private void LoadToTable(int PageNumber)
{
this.TabResult.Rows.Clear(); GoogleSearchService a = new GoogleSearchService();
GoogleSearchResult b = a.doGoogleSearch("eD2A9vlQFHLGnNPZPOLJfQQhOsqYg+Mh",this.Txt.Text,PageNumber*10,10,false,"",false,this.DplLang.SelectedItem.Value,"UTF-8","UTF-8"); foreach (ResultElement result in b.resultElements)
{
this.TabResult.Rows.Add(new TableRow());
this.TabResult.Rows[this.TabResult.Rows.Count-1].Cells.Add(new TableCell());
this.TabResult.Rows[this.TabResult.Rows.Count-1].Cells[0].Text = ""; this.TabResult.Rows[this.TabResult.Rows.Count-1].Cells[0].Text += "<font color='#82582F'>"+result.title+"</font><br><br>";
this.TabResult.Rows[this.TabResult.Rows.Count-1].Cells[0].Text += result.snippet+"<br><br>";
this.TabResult.Rows[this.TabResult.Rows.Count-1].Cells[0].Text += "<font color='#82582F'>Link:</font> <a target='_blank' href='"+result.URL+"'>"+result.URL+"</a><br>";
this.TabResult.Rows[this.TabResult.Rows.Count-1].Cells[0].Text += "<font color='#82582F'>- <font color='orange'>"+this.TabResult.Rows.Count+"</font> ---------------<font color='#CCCCCC'>----------------------</font>----------------------------------------------------------------</font><br>";
}
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{    
this.LinkButton2.Click += new System.EventHandler(this.LinkButton2_Click);
this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
this.Txt.TextChanged += new System.EventHandler(this.Txt_TextChanged);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void LinkButton1_Click(object sender, System.EventArgs e)
{
int pagenum = (Int32.Parse(this.Label1.Text)+1);
this.LoadToTable(pagenum);
this.Label1.Text = pagenum.ToString();
} private void LinkButton2_Click(object sender, System.EventArgs e)
{
int pagenum = (Int32.Parse(this.Label1.Text)-1);
if (Int32.Parse(this.Label1.Text)<=0)
{
this.Label1.Text = "0";
}
else
{
this.LoadToTable(pagenum);
this.Label1.Text = pagenum.ToString();
}
} private void Txt_TextChanged(object sender, System.EventArgs e)
{
this.Label1.Text = "0";
}
}
}