博客
关于我
强烈建议你试试无所不能的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

你可能感兴趣的文章
OO第一单元总结
查看>>
[原创]你所需要了解的软件测试相关标准
查看>>
最近这么火的iOS视频直播
查看>>
程序员陪女朋友自拍杆哪个好?自拍杆品牌推荐
查看>>
output 参数在存储过程中的用法
查看>>
大数加法和乘法(高精度)
查看>>
利用SynchronizationContext.Current在线程间同步上下文
查看>>
单片机reg51.h头文件详解(1)
查看>>
python各种类型转换-int,str,char,float,ord,hex,oct等
查看>>
sublime Text3 快捷键
查看>>
HDU - 3416-Marriage Match IV (最大流 + 最短路)
查看>>
19 年书单
查看>>
力扣——各位相加
查看>>
规范 : Sql statusEnum
查看>>
jQuery的.live()和.die() 使用介绍
查看>>
mybatis
查看>>
我该怎么安排下属的工作-项目经理如何分配任务
查看>>
Chord算法(原理)
查看>>
cocos2d-html5
查看>>
Ubuntu 14.04 Android 使用Maven二 创建自己的Mavenproject
查看>>