博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Using Bing Search Service over SOAP Protocol in an ASP.NET Web Application
阅读量:4546 次
发布时间:2019-06-08

本文共 6454 字,大约阅读时间需要 21 分钟。

Introduction

This walkthrough shows how to use Bing search as a Web service in an ASP.NET Web application. The Bing search features are invoked by the ASP.NET Web application using SOAP protocol over HTTP.

You can also use XML and JSON to invoke the service. We’ll have related examples at a later time.

This walkthrough shows you how to perform the following tasks:

  • Create a client Web application to interact with BING service.
  • Add the reference to the Bing search service.
  • Perform live search by using Bing SourceTypes.
Bing Service Background

Complex problems such as indexing, relevance logic, and hosting issues such as CPU and storage are solved in transparent way to your application by having the ability to use the BING features as a Web service. This article offers a starting point for adding the service to your application.

Remember that a Web service is a component on a Web server that a client application can call by making HTTP requests across the Web. If you want some good explanation about this subject, see this MSDN article .

By using the service you can integrate the following features in your application:

  • Retrieve information from the Internet.
  • Add advertisements to your application.
  • Improve and enhance search requests and results.
  • Find location-specific information.
  • Translate terms and blocks of text.

You interact with the BING Service through the . 

Each of the previous feature is associated with one or more Bing API SourceTypes. A SourceType is a source of information accessible via the .   An overall description of these SourceTypes can be find on MSDN at this location: .

Prerequisites

In order to complete the example in this topic, you need the following:

  • Visual Studio 2010.
  • The ability to send requests using the Simple Object Access Protocol (SOAP) 1.1 and the Hyper Text Transfer Protocol (HTTP 1.1)
  • The ability to parse SOAP and XML

Creating a Web Application

This section shows how to create a Web application that will use the Bing search service.

To create an ASP.NET Web application

  1. Start Visual Studio 2010
  2. In the File menu, click New, and then click Project.
  3. The New Project dialog box is displayed.
  4. Under Installed Templates, in the left pane, select Visual Basic or Visual C#.
  5. In the right pane, select ASP.NET Web Application.
  6. In the Location box enter the name of the folder where you want to keep the Web application. For example, enter the folder name C:\CS\SOAP\WebApplications
  7. In the Name dialog box enter the name of the project. For example, enter the name UsingBingAPI.
  8. Click OK.
  9. An ASP.NET application is created.

Adding a Web Reference to Bing Search Service

This section shows how to add a Web reference to the Bing search service. In order to do that, you use a Web service discovery process by which the client application locates the service and obtains its description. The process of Web service discovery in Visual Studio involves interrogating a Web site to locate the service description, which is an XML document that uses the Web Services Description Language (WSDL).

When you add a Web reference to a project, Visual Studio generates a proxy class that provides a local representation of the Web service, which allows the client code to interface with the Web service. You can access Web service methods by calling the methods in the proxy class. The proxy class handles the communication between the client application and the Web service itself.

To add a Web reference to Bing Search Service

  1. In Solution Explorer , right-click the project name, and then click Add Web Reference button.
  2. In the Add Web Reference panel, in the URL box enter the following value: .
  3. Click GO .
  4. If the process has been added successfully a message is displayed saying that “1 Service Found: Search” and the Web reference is: net.live.search.api.
  5. Click Add Reference button.
  6. A Web References folder is added to the project that contains the reference to the live search service API.
  7. Also, the Web.config file is updated to contains address information about the soap.asmx service. The following is an example of the configuration update.

 

 

Performing Search by Using Bing ServiceTypes

This section shows the code that enables the user to choose the desired Bing ServiceType to perform live search. For simplicity only the following types are used:

SourceType

Function

Web

Retrieve information from the Internet

Phonebook

Find location specific information

Selecting the ServiceType to Use
  1. In Solution Explorer , open the default.aspx page. Then add the following markup.
 
Create the Code to Interact with the Web ServiceType
  1. In Solution Explorer , right-click the project name then click Add and select New Item.
  2. In the Installed Templates dialog, select Web Form.
  3. In the Name box enter WebSourceType.aspx.
  4. Click the Add button.
  5. In the newly created WebSourceType.aspx page enter the following markup and save the file.

Using the Web SourceType Over the SOAP Protocol

This example shows how to perform the following tasks:

See Also

BING API
For more information, see Technical Notes
  1. In Solution Explorer , open the code behind file WebSourceType.aspx.cs and add the following code and save the file.
TableRow tRow               WebResultID               tCell               System               builder builder[i] = Convert.ToChar(“[");                   }                   i               tCell               tRow           }       }       }
  1. In Solution Explorer , right-click the project name then click Add and select New Item.
  2. In the Installed Templates dialog, select Web Form.
  3. In the Name box enter UsingWebSourceType.cs.
  4. Click the Add button.
  5. In the newly created file enter the following code and save the file.
}             XmlNodeList errors                 }             }         }     } }

Testing the Web Application

This section shows the steps to perform to test the application.

  1. Build the Web application.
  2. In Solution Explorer right click on default.aspx.
  3. Click the Using the Web SourceType over the SOAP Protocol link
  4. The Web ServiceType search results are displayed.

We are done.

A complete Visual Studio project is attached next. Please download and play with it.

I appreciate your feedback.

See Also

 

source:

转载于:https://www.cnblogs.com/big4panda/archive/2010/10/08/6417581.html

你可能感兴趣的文章
Android数据库高手秘籍(一)——SQLite命令
查看>>
[Oracle] 分析功能(1)- 语法
查看>>
Android ViewPager使用具体解释
查看>>
UNIX下改动时间简单一例
查看>>
秒杀多线程第四篇 一个经典的多线程同步问题
查看>>
局域网共享磁盘或文件夹访问
查看>>
LINUX 必知必会检测表--通读无关语言
查看>>
关于iOS和OS X废弃的API你需要知道的一切
查看>>
WEBI 中的参数传递
查看>>
IOS知识小记
查看>>
Memecached缓存原理及基本操作、分布式(一致性hash)
查看>>
编程常见的三种命名法:骆驼命名法,帕斯卡命名法和匈牙利命名法
查看>>
Best Time to Buy and Sell Stock III
查看>>
图片中添加箭头【使用PPT实现】
查看>>
鹊桥会--秦观
查看>>
用 Java 技术创建 RESTful Web 服务/@Path@Produces@PathParam
查看>>
STM32 GPIO寄存器 IDR ODR BSRR BRR
查看>>
名企面试官精讲典型编程题之C++篇
查看>>
SublimeText3常用操作
查看>>
008---re正则模块
查看>>