Here's a very quick code sample that you can use to add Bing API search capabilities to your .NET application. You will need to sign-up and get an API key for this to work, but it's free and you can use an existing Live ID if you have one (for example, for MSDN).
The example here was taken from a Console application. You will need to integrate it in to your own application (if you just want to see it working, create your own console application and paste it in to the main function).
You need to add a reference to the SOAP service to your application. Right click the 'References' folder and choose 'Add Service Reference'. The address is: "http://api.bing.net/search.wsdl?Version=2.2&AppID=" with your AppId appended to the end.
string AppId = ""; // enter your AppId key here! string query = "michael jackson"; using (BingPortTypeClient client = new BingPortTypeClient()) { var request = new SearchRequest(); request.AppId = AppId; request.Sources = new SourceType[] { SourceType.Web }; request.Query = query; SearchResponse response = client.Search(request); if (response.Web != null && response.Web.Results.Count() > 0) { var pos = 0; foreach (var r in response.Web.Results) { pos++; Console.WriteLine(pos + ". " + r.Title); Console.WriteLine(r.Url); Console.WriteLine(r.Description); Console.WriteLine(); } } } Console.ReadLine();
The reason I post this code here is that Microsoft haven't yet updated MSDN with any code samples for the new API yet, and it took me a while to realise that the SOAP client was BingPortTypeClient.
About
We are a small British company that produces business-oriented software and solutions. These articles are a product of our daily work - information that we think might be useful to share. We hope you find them useful.
Our Software
These are some of our products. Several are open source, some are web-based and others are proprietary:
Categories
- .NET (10)
- Apple (2)
- Business (5)
- CSS (1)
- HTML (2)
- Innovation (4)
- Java (4)
- Javascript (1)
- Leadership (1)
- MySQL (2)
- Oracle (6)
- Postgres (1)
- Programming (5)
- Rails (4)
- Ruby (10)
- SQL Server (9)
- Subversion (1)
- Web (5)
- Windows Server (2)
Archives
- July 2010 (2)
- September 2009 (5)
- August 2009 (1)
- July 2009 (12)
- June 2009 (16)
- May 2009 (3)