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

你可能感兴趣的文章
判断浏览器内核(转)
查看>>
GitHub for Windows提交失败“failed to sync this branch”
查看>>
linux 安装 git
查看>>
Margin
查看>>
完成登录与注册页面的前端
查看>>
centos 源码安装php7
查看>>
Log4j详细教程
查看>>
UVa-1368-DNA序列
查看>>
ConfigParser模块
查看>>
如何开发优质的 Flutter App:Flutter App 软件测试指南
查看>>
决胜Flutter 第一章 熟悉战场
查看>>
如何开发优质的 Flutter App:Flutter App 软件调试指南
查看>>
决胜经典算法之冒泡排序
查看>>
决胜经典算法之选择排序
查看>>
单元格数据类型
查看>>
mysql表设计---时间类型
查看>>
wamp服务器
查看>>
Codeforces 1144G Two Merged Sequences dp
查看>>
STL内存分配方式
查看>>
NS2移动节点
查看>>