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

你可能感兴趣的文章
centos 安装mysql
查看>>
Redis 禁用FLUSHALL FLUSHDB KEYS 命令
查看>>
Matlab中imread函数使用报错“不应为MATLAB 表达式”分析
查看>>
MFC ADO数据库操作
查看>>
图像质量评价-NQM和WPSNR
查看>>
面试准备——相关知识
查看>>
每日一字:悟
查看>>
CentOS7.6安装稳定版Nginx
查看>>
LeetCode 1002. Find Common Characters (查找常用字符)
查看>>
建立隐藏管理员用户
查看>>
android设置图文提醒功能
查看>>
ajax跨域提交
查看>>
完成登录与注册页面的前端
查看>>
Mac下source tree 下的安装
查看>>
Q学习原理及例子
查看>>
rpmbuild 源码打包clickhouse,附带打好的rpm包下载地址
查看>>
软件体系结构原理、方法与实践总结
查看>>
2017-2018-1 《程序设计与数据结构》第3周学习总结
查看>>
一些基础语法
查看>>
win10企业版无法访问共享文件夹
查看>>