Notes Index
Consuming Web Services
Web Service providers are popping up on the Web with the intention of providing services for a fee (and occasionally for free).
Some of the biggest Web sites provide Web services to software developers
In addition, collections of Web services are also available on the Web
Google Search
A tutorial on Using the Google Web Service with the .NET platform is available over the Web. In addition, Google makes available Web API's reference page along with FAQS, terms, newsgroup, and help pages.
using com.
google.
api;
...
protected void GoogleSearchButton_Click
(object sender,
EventArgs e
)
{
GoogleSearchService ws =
new GoogleSearchService
();
try
{
GoogleSearchResult result = ws.
doGoogleSearch(
"EPZGy8JQFHKV42eZFr2uSZKnrDLrwrM7",
TextBox1.
Text,
0,
5,
false,
"",
false,
"",
"",
"");
foreach (ResultElement re
in result.
resultElements)
{
string t = re.
title;
string u = re.
URL;
string s = re.
snippet;
Label1.
Text +=
String.
Format(
"<p>{0}<br />{1}<br />{2}</n>",
t, u, s
);
}
}
catch (System.
Web.
Services.
Protocols.
SoapException ex
)
{
Label1.
Text = ex.
Message;
}
}
Consuming XML Data
Quite often, the data returned from a Web service is XML. The consuming page may need to parse the XML elements to access the data
protected void GetCityInfoButton_Click(object sender,
EventArgs e)
{
try
{
net.webservicex.www.USZip ws =
new net.webservicex.www.USZip();
XmlNode n = ws.GetInfoByZIP("98926");
XmlNode state = n.SelectSingleNode("Table/STATE");
this.Label1.Text = state.InnerText;
}
catch (Exception ex)
{
this.StateLabel.Text = ex.Message;
}
}
Windows Live
Windows Live is the latest push by Microsoft to provide Web services.
protected void SearchButton_Click(object sender, EventArgs e)
{
// Create instance of MSN Search Services
com.msn.search.soap.MSNSearchService search = new com.msn.search.soap.MSNSearchService();
SourceRequest webSource = new SourceRequest();
webSource.Source = SourceType.Web;
// Build the Search Request
SearchRequest request = new SearchRequest();
request.AppID = "8CB37361787BDF661FCACE46ED1207301A8565F0";
request.Requests = new SourceRequest[] {webSource};
request.Query = TextBox1.Text;
request.CultureInfo = "en-US";
// Execute Search
SearchResponse response = search.Search(request);
GridView1.DataSource = response.Responses[0].Results;
GridView1.DataBind();
}