Wednesday, September 30, 2009

Using Bing API in .NET

To start using the Bing API, you will need to apply for an AppID from Microsoft. With the AppID in hand, you can have Visual Studio get the WSDL and auto-generate .NET classes for your use. Follow these steps (which are for Visual Studio 2008):

1. Right-click your project references and choose Add Service Reference.
2. Click the Advanced button.
3. Click Add Web Reference.
4. Enter http://api.bing.net/search.wsdl?AppID=YourAppId&Version=2.2 for the URL. Make sure to put your correct AppID in there.
5. Change the reference name if you want; I left it as-is.
6. Click Go and, when the process completes, click Add Web Reference.

If you prefer, you can use XML or JSON to access Bing, although the SOAP interface makes the most sense for the majority of .NET apps, thanks to Visual Studio’s integration with SOAP services.

You’re ready to get to work. To start using the newly created references, add the appropriate using (for C# folks) or Imports (for VB.NET) statement to your code that needs to use Bing. The full name is your default namespace for the project, plus the service reference. In this case, my project’s namespace is TestProject, so this is my line to bring it in:

using TestProject.net.live.search.api;

I’ll show you how to create a basic request for Web results; however, you should know that Bing is capable of providing various kinds of results, including videos, images, and phonebooks, and you can have a search request look for multiple types at the same time. I will leave it as an exercise for you to try the other search types out there.

All search requests share some basic required parameters and offer additional parameters of their own. The required parameters are:

* AppID (string): The AppID you were issued.
* Query (string): The query you want to run; this is identical to what you would enter at the Bing site to perform a search.
* Sources (Sources[]): An array of Sources (an enumeration in the namespace) indicating what type(s) of search to perform.

This is a simple method that takes a query and performs a search:

private void Lookup(string Query)
{
using (var service = new LiveSearchService())
{
try
{
var request = new SearchRequest();

// Common request fields (required)
request.AppId = "BingAppID";
request.Query = Query;
request.Sources = new SourceType[] { SourceType.Web };
var response = service.Search(request);

if (response.Web.Results == null)
{
return;
}
}
catch (System.Web.Services.Protocols.SoapException ex)
{
// Swallow exceptions for the time being
}
catch (System.Net.WebException ex)
{
// Swallow exceptions for the time being
}
}
}

Attribution: This is a greatly stripped down, modified version of the sample code in the Bing documentation. This is all you need to do a search.

From here, you can work with the results of the query. I found LINQ to be a great way to work with the results. In my application, I created a Results class that encapsulated not only the information I needed from Bing but also my post-search processing. So, I populated a List with a simple LINQ query:

results = (from result in response.Web.Results
select new Result(result.Url, result.DisplayUrl, result.Title, 0, 0, new
List())).ToList();

Some of the items populating the Result objects in the list come from the Bing results in the response object, and some of the items are just initialization values for my later processing to build on.

With this simple piece of code, you are well on your way to writing a Bing-enabled application.To start using the Bing API, you will need to apply for an AppID from Microsoft. With the AppID in hand, you can have Visual Studio get the WSDL and auto-generate .NET classes for your use. Follow these steps (which are for Visual Studio 2008):

1. Right-click your project references and choose Add Service Reference.
2. Click the Advanced button.
3. Click Add Web Reference.
4. Enter http://api.bing.net/search.wsdl?AppID=YourAppId&Version=2.2 for the URL. Make sure to put your correct AppID in there.
5. Change the reference name if you want; I left it as-is.
6. Click Go and, when the process completes, click Add Web Reference.

If you prefer, you can use XML or JSON to access Bing, although the SOAP interface makes the most sense for the majority of .NET apps, thanks to Visual Studio’s integration with SOAP services.

You’re ready to get to work. To start using the newly created references, add the appropriate using (for C# folks) or Imports (for VB.NET) statement to your code that needs to use Bing. The full name is your default namespace for the project, plus the service reference. In this case, my project’s namespace is TestProject, so this is my line to bring it in:

using TestProject.net.live.search.api;

I’ll show you how to create a basic request for Web results; however, you should know that Bing is capable of providing various kinds of results, including videos, images, and phonebooks, and you can have a search request look for multiple types at the same time. I will leave it as an exercise for you to try the other search types out there.

All search requests share some basic required parameters and offer additional parameters of their own. The required parameters are:

* AppID (string): The AppID you were issued.
* Query (string): The query you want to run; this is identical to what you would enter at the Bing site to perform a search.
* Sources (Sources[]): An array of Sources (an enumeration in the namespace) indicating what type(s) of search to perform.

This is a simple method that takes a query and performs a search:

private void Lookup(string Query)
{
using (var service = new LiveSearchService())
{
try
{
var request = new SearchRequest();

// Common request fields (required)
request.AppId = "BingAppID";
request.Query = Query;
request.Sources = new SourceType[] { SourceType.Web };
var response = service.Search(request);

if (response.Web.Results == null)
{
return;
}
}
catch (System.Web.Services.Protocols.SoapException ex)
{
// Swallow exceptions for the time being
}
catch (System.Net.WebException ex)
{
// Swallow exceptions for the time being
}
}
}

Attribution: This is a greatly stripped down, modified version of the sample code in the Bing documentation. This is all you need to do a search.

From here, you can work with the results of the query. I found LINQ to be a great way to work with the results. In my application, I created a Results class that encapsulated not only the information I needed from Bing but also my post-search processing. So, I populated a List with a simple LINQ query:

results = (from result in response.Web.Results
select new Result(result.Url, result.DisplayUrl, result.Title, 0, 0, new
List())).ToList();

Some of the items populating the Result objects in the list come from the Bing results in the response object, and some of the items are just initialization values for my later processing to build on.

With this simple piece of code, you are well on your way to writing a Bing-enabled application.

Reference from http://blogs.techrepublic.com.com/programming-and-development/?p=1713&tag=nl.e055 by Justin James
read more...

Wednesday, September 16, 2009

Scott Cole's Best Abs on Earth





read more...

Windows Vista Tips & Tricks

Some Useful tips and tricks in Windows Vista





read more...

Speed up your browsing of Windows 2000 & XP machines

Here's a great tip to speed up your browsing of Windows XP machines. Its actually a fix to a bug installed as default in Windows 2000 that scans shared files for Scheduled Tasks. And it turns out that you can experience a delay as long as 30 seconds when you try to view shared files across a network because Windows 2000 is using the extra time to search the remote computer for any Scheduled Tasks. Note that though the fix is originally intended for only those affected, Windows 2000 users will experience that the actual browsing speed of both the Internet & Windows Explorers improve significantly after applying it since it doesn't search for Scheduled Tasks anymore. Here's how :Open up the Registry and go to :
HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/Current Version/Explorer/RemoteComputer/NameSpace
Under that branch, select the key :
{D6277990-4C6A-11CF-8D87-00AA0060F5BF}
and delete it.
This is key that instructs Windows to search for Scheduled Tasks. If you like you may want to export the exact branch so that you can restore the key if necessary.
This fix is so effective that it doesn't require a reboot and you can almost immediately determine yourself how much it speeds up your browsing processes.
read more...