It must be hard on Windows Mobile)

Source: Internet
Author: User

It must be hard on Windows Mobile)

Freesc Huang

Http://fox23.cnblogs.com

Abstract: A while ago, Bing had been a hot topic, and its market share reached more than 18% at a time, not only because of Microsoft's powerful publicity campaign, there is also the origin of "AV door" ("must be hard ???) Although the search quality is mixed, Bing provides more and more extensive Bing APIs, which are worth looking forward. If you do not have any idea about Bing APIs, we recommend that you first read this article by Ma Ning. This article demonstrates how to use Bing API 2.x on mobile devices to create a simple news search.

I. Bing mobile version

Bing's mobile version has been released. You can enter m.bing.com in the address bar of your mobile browser to access its web version:

 

You can also download Bing for Windows Mobile client via http://mobile.search.live.com/client/download_manual.aspx

Shows the effect:

 

Currently, most services are only available in the United States, Britain, and Japan.

 

2. Use Bing API in Windows Mobile applications

Before everything starts, first you have to apply for an appid (http://www.bing.com/developers/createapp.aspx) and keep it properly. Bing currently provides a wide range of API services (sourcetypes), including web pages, advertisements, images, videos, news, phone books, translation, and spelling checks. Each category is a relatively independent vertical search. You canProgramUse one or more of these sourcetypes to construct a custom search-related application.

Here I want to write a simple news search. Its basic functions are as follows:

1. The first 10 records of each query are returned.

2. Provide Related searches

3. You can view the publishing time and news segment of the search results.

The interface consists of a search box (tbsearchstring), a ComboBox (cbrelated) used to display related queries, A listview (lvresult) used to display results, and two softkey buttons ,:

OK, next we first Add a reference to bing web service, service URL: http://api.search.live.net/search.wsdl

 

When the search button is pressed, execute the followingCode:

// Clear listview and combbox
Listview1.items. Clear ();
Listview1.tag =   Null ;
Cbrelated. Items. Clear ();

Using (Livesearchservice Service =   New Livesearchservice ())
{
// Buildrequest is used to configure our query requests. Don't worry, I will mention it soon
Searchrequest request = Buildrequest ();
Searchresponse response = Service. Search (request );

// Displayresponse is used to organize the display of query results
Displayresponse (response );
}

 

Buildrequest is defined as follows:

Buildrequest
Private Searchrequest buildrequest ()
{
Searchrequest searchreq =   New Searchrequest ();

// Note that appid must be modified on your own.
Searchreq. appid = Properties. Resources. appid;
Searchreq. Query = Tbsearchstring. text;

// Sourcetype determines the type of this query
Searchreq. Sources =   New Sourcetype [] {Sourcetype. News, sourcetype. relatedsearch} ;
Searchreq. Market =   " En-US " ;

// Configure the number and sorting method of news
Searchreq. News =   New Newsrequest ();
Searchreq. News. Count =   10 ;
Searchreq. News. countspecified =   True ;
Searchreq. News. sortby = Newssortoption. relevance;
Searchreq. News. sortbyspecified =   True ;

Return Searchreq;
}

 

Next, in order to save the query results conveniently and securely according to our needs, we add a class mynewsresult:

Public   Class Mynewsresult
{
Public   String Date {Get;Set;} // Date
Public   String Title {Get;Set;} // Title
Public   String Snippet {Get;Set;} // News segment Selection
}

 

Next, let's take a look at the displayresponse function:

Displayresponse
Private   Void Displayresponse (searchresponse response)
{
If (Response. News ! =   Null   &&
Response. News. Results ! =   Null   &&
Response. News. Results. Length >   0 )
{
// Extract the information we need and store each result in the form of mynewsresult.
VaR results = From bingresults In Response. News. Results
Select New Mynewsresult () {date = bingresults. date,
title = bingresults. title,
snippet = bingresults. snippet} ;

// Save the result to the listview tag for continued use
Lvresult. Tag = Results. toarray ();

// Save related news query to ComboBox
If (Response. News. relatedsearches ! =   Null   &&  
Response. News. relatedsearches. Length >   0 )
{
Foreach (VAR rs In Response. News. relatedsearches)
{
Cbrelated. Items. Add (Rs. Title );
}
}
// Add the expected result title to listview.
Foreach (VAR R In (Mynewsresult []) lvresult. Tag)
{
Lvresult. Items. Add (NewListviewitem (R. Title. tostring ()));
}
}
}

 

Finally, I want to display the date and segment of the news when selecting an item in the listview. Therefore, the following code is added to the itemactivate event processing function of lvresult:

Mynewsresult [] NR = (Mynewsresult []) lvresult. Tag;
If (NR ! =   Null )
{
MessageBox. Show (NR [lvresult. selectedindices [0]. Snippet,
NR [lvresult. selectedindices [0]. Date );
}

 

At this point, we have completed the main work (complete codeArticleDownload at the end ). Let's take a look at the running effect:

Related search:

Click here to download the complete code.

Finally, I have an exercise question for interested friends:

How to Use Bing to create a GPS-based vertical search?

(Tip 1: searchrequest has the longitude and latitude attributes)

(Tip 2: Refer to bing map SDK http://msdn.microsoft.com/en-us/library/dd877180.aspx)

(Tip 3: I don't have any ready-made code. You have to do it yourself)

Try it ;-)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.