Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


Sharepoint TechCon

Reader rating:
Click here to read 7 comments about this article.
Article source: CoDe (2010 May/Jun)


Article Pages:  1  2 3 4 5 - Next >


Exploring the Bing API Using WCF

The TV commercials took me and many others by surprise. A stream-of-conscienceless-style ad that had our brains struggling to catch up with the next topic that the next person blurted out. Funny enough, the bouncing from topic to topic by the actors in the commercial seem to be a familiar metaphor to anyone that has traversed search results at one time or another. And at the end, a familiar logo appears: Microsoft, followed by a not-so-familiar one: Bing.

Microsoft’s new search engine, or more to their own description, decision engine, seemed to come out of nowhere. Indeed, even as a Microsoft MVP who has the luxury of knowing about new products slightly ahead of the public, I was taken by surprise (as where many of my fellow MVPs). Still, it came as a pleasant and well-received surprise because upon trying it out we discovered it works quite well. Bing is not only a good search engine, but it has a very attractive user interface while still maintaining the simplicity that we come to expect from a search engine.

"
Microsoft’s revamp of its Internet-Search end of the business is as developer-friendly as many of their other products
"

Not surprisingly, Microsoft’s revamp of its Internet-Search end of the business is as developer friendly as many of their other products. Bing exposes quite a robust API that allows developers to use all its services from their own applications, whether they are on a Web or rich-client platform. The API allows for the use of either SOAP or REST protocols, and I’ll cover both in this article for your programming pleasure. Surprisingly, I’ve yet to come across an article on the Bing API or online code samples that use WCF to access it. I think you’ll find this article refreshing in the way that it provides a very different coverage from other documentation out there. WCF is the preferred technology to use when dealing with connected systems, and Bing certainly fits into that category. It only made sense to me that the two should be able to play nice together, so in this article I emphasize using WCF.

"
“WCF is the preferred technology to use when dealing with connected systems and Bing certainly fits into that category.”
"

Which one of the API protocols you use is really a matter of preference and perhaps usage needs. Applications that expose a REST API tend to serve a larger variety of platforms, provided the data they expose is POX (plain old XML). While the Bing REST API can expose either POX or JSON (JavaScript Object Notation), the XML data it serves contains processing instructions that WCF does not seem to like, and I’ve yet to figure out a way around it. In fact, all the sample code you’ll find out there (if you Bing for it of course) that uses the XML data will read it using old fashioned Web request techniques and use an XML parser to take it apart. And in fact, this is the technique that the Bing documentation itself uses.

I’m a WCF guy so I tend to like the REST API over the SOAP one simply because it gives me the ability to name the API members to my own liking and not be forced to adhere to the exact object model conventions defined in the SOAP API; but I’ll show you how to do that later. The SOAP API, however, is definitely easier to get started with and a lot quicker. You’ll see that I’ll use WCF in both techniques to access Bing, but it will be much more evident when I get to the REST API.

What the API Provides

The Bing API exposes functionality for many areas of the Bing engine including searching for text, images, videos, news, and even a specific mobile device-oriented search. But this is just search I’m talking about. Bing itself provides functionality for managing advertising, spell checking, location services, and translation services. It also provides an instant-answer search that uses the Encarta online encyclopedia. Each of these types of functionality is known as a Source Type and will be continuously discussed throughout the rest of this article.

Web Searching

The more common use for the Bing search engine is for standard Web queries. The API lets you perform Web queries that return site links and content, images, videos, or new sources.

This kind of search is directly equivalent to typing in search text on the Bing home page (or its images or videos section) and pressing the search button. The Bing site also has a News section which lets you type in some text and get back hits on various news sources relevant to your search text. The Source Types that corresponds to these types of searches are Web, Image, Video, and News.

On the Bing Web site, you can ask Bing questions that start with phrases like “what is” or “what does … mean”. In these cases, Bing will return hits using the Microsoft Encarta encyclopedia. When using the Bing API, this becomes a separate Source Type called InstantAnswer. When using the API in this manner, you can send questions like “How many ounces in a pound” or “What is 78f in Celsius.” You can also ask for word definitions like “What does bloviate mean?” This section of the API also lets you access flight information by sending in a carrier code and flight number, like “CO1579.”

Ads

Bing also exposes the ads that come up when you execute a search as a specific set of search results that you can access with the API. For whatever reason, you may want to show ads from Bing in your application or your site, based on the content currently showing on the page or the content of a particular Windows form you’re on. I know, I know; why would you want this feature in your rich client apps? I have no clue. It’s there so you can use it if you’d like. The Ads section of the API is a little more involved and requires membership information beyond the scope of this article.

Spell Checking

Bing’s spell-check capability lets you send in a word or even a full sentence and returns the corrected text, if any of the words are recognized as being misspelled. For connected applications, this can add some tremendous capabilities for your users, especially if they spel like me.

Location Services

Bing’s location services let you send in either a name or a place of business, as well as intelligent phrases like “hotels near Seattle” or “Italian restaurants near 07035.” The engine will return result data responding to your specific request which not only includes name and information about each item but also a map link that uses Bing Maps to map out each resulting location.

Translation Services

Last, but not least, we have Bing’s translation services. This part of the engine lets you send in a word, phrase, or sentence along with both a source and target language (using standard language codes). The results are simple: a direct translation of your query from the source language into the target language. Of course, it’s entirely your responsibility that the query text you send in is in the language you designate as the source language.

So now that you know what the Bing API has to offer, let’s see how to actually employ these services using the easy-to-use SOAP API.

&

By: Miguel Castro

Miguel is an architect with IDesign who specializes in architecture consulting and building .NET solutions. He is a Microsoft MVP and INETA speaker and has been a software developer for over 22 years. With a Microsoft background that goes all the way back to VB 1.0 (and QuickBasic in fact), Miguel jumped on .NET as soon as the first public Beta was released and has provided .NET solutions for clients around the country in a variety of industries. He considers himself to be a .NET Developer and Architect and has equal love for both VB and C#, and no tolerance for language bigotry. He’s spoken at numerous user groups around the country as well as developer conferences.

He’s the author of the CodeBreeze code-generator, which among things can be found on his Web site:

www.steelbluesolutions.com

Miguel currently lives in Lincoln Park, NJ with his wife Elena and his daughter Victoria.

subscriptions@infotekcg.com



Article Pages:  1  2 3 4 5 - Next Page: 'Using the Bing SOAP API' >>

Page 1: Exploring the Bing API Using WCF
Page 2: Using the Bing SOAP API
Page 3: The Bing Object Model(The Response)
Page 4: Multiple Searches
Page 5: The Public API

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
4.2 out of 5

20 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      AppsWorld Europe

 

SSWUG