通过 SSIS 中的 Web 服务任务使用通过 SQL Server HTTP Endpoint 创建的 Web 服务






4.75/5 (11投票s)
在本文中,我们将了解如何通过 SSIS 的 Web 服务任务使用通过 HTTP Endpoint 公开的 Web 服务。
通过 SSIS 中的 Web 服务任务使用通过 SQL Server HTTP Endpoint 创建的 Web 服务
目录
引言
Web 服务允许各种应用程序相互通信。它们基于某些标准
- XML -> 表示数据
- SOAP (Simple Object Access Protocol) -> 数据交换
- WSDL (Web Service Description Language) -> 描述 Web 服务的各项功能。
HTTP Endpoint 是 SQL Server 中的一个对象,SQL Server 使用它在网络上进行通信。它包含了 Web 方法(通常是数据库中执行的存储过程(T-SQL 或 CLR)),Web 服务会查询这些方法。
SSIS 中的 Web 服务任务用于执行 Web 服务方法。
在本文中,我们将探讨如何通过 SSIS Web 服务任务来调用通过 HTTP Endpoint 公开的 Web 服务方法。
数据源
为了进行此实验,我们将使用以下脚本生成并填充名为 (tbl_Players) 的 Players 表。
-- Drop the table if it exists IF EXISTS (SELECT * FROM sys.objects WHERE name = N'tbl_Players' AND type = 'U') DROP TABLE tbl_Players GO SET ANSI_NULLS ON GO --Create the table CREATE TABLE tbl_Players ( PlayerID INT IDENTITY, PlayerName VARCHAR(15), BelongsTo VARCHAR(15), MatchPlayed INT, RunsMade INT, WicketsTaken INT, FeePerMatch NUMERIC(16,2) ) --Insert the records INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('A. Won','India',10,440,10, 1000000) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('A. Cricket','India',10,50,17, 400000) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('B. Dhanman','India',10,650,0,3600000) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('C. Barsat','India',10,950,0,5000000) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('A. Mirza','India',2,3,38, 3600000) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('M. Karol','US',15,44,4, 2000000) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('Z. Hamsa','US',3,580,0, 400) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('K. Loly','US',6,500,12,800000) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('S. Summer','US',87,50,8,1230000) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('J.June','US',12,510,9, 4988000) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('A.Namaki','Australia',1,4,180, 999999) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('Z. Samaki','Australia',2,6,147, 888888) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('MS. Kaki','Australia',40,66,0,1234) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('S. Boon','Australia',170,888,10,890) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('DC. Shane','Australia',28,39,338, 4444499) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('S. Noami','Singapore',165,484,45, 5678) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('Z. Biswas','Singapore',73,51,50, 22222) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('K. Dolly','Singapore',65,59,1,99999) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('S. Winter','Singapore',7,50,8,12) INSERT INTO tbl_Players(PlayerName, BelongsTo, MatchPlayed,RunsMade,WicketsTaken,FeePerMatch) VALUES('J.August','Singapore',9,99,98, 890)
我们还将在数据库中创建以下存储过程,其脚本如下
If Exists (Select * from sys.objects where name = 'usp_SelectPlayerRecords' and type = 'P') Drop Procedure usp_SelectPlayerRecords Go -- Create the stored procedure Create Procedure [dbo].[usp_SelectPlayerRecords] As Begin Select PlayerID ,PlayerName , BelongsTo , MatchPlayed ,RunsMade ,WicketsTaken ,FeePerMatch From tbl_Players End
(A) Endpoint 创建
让我们执行以下脚本来创建 endpoint:
IF EXISTS ( SELECT NAME FROM sys.http_endpoints WHERE NAME = N'PlayerRecord_EP' ) DROP ENDPOINT PlayerRecord_EP GO CREATE ENDPOINT [PlayerRecord_EP] STATE=STARTED AS HTTP ( PATH=N'/PlayerName' , PORTS = (CLEAR) ,AUTHENTICATION = (INTEGRATED) , SITE=N'localhost' , CLEAR_PORT = 8000 ) FOR SOAP ( WEBMETHOD 'PlayerList' ( NAME=N'[SSISExperiments].[dbo].[usp_SelectPlayerRecords]') , BATCHES=DISABLED , WSDL=DEFAULT , DATABASE=N'SSISExperiments' , NAMESPACE=N'http://SSISExperiments/Players' ) GO
代码解释
AS HTTP 部分标识了路径、端口和身份验证方法。PATH 始终以正斜杠 (/) 开始,并标识根目录下的路径。在此示例中,我们创建一个路径为 '/PlayerName' 的 endpoint,该 endpoint 在本地服务器上可用。因此,完整路径将是 https://:8000/PlayerName。PORTS 设置为 CLEAR 表示我们使用 HTTP 和端口 80。
FOR SOAP 部分标识了 Web 方法、WSDL 和数据库。WEBMETHOD 用于标识通过 endpoint 调用的存储过程。
运行脚本将在 Server Objects 中创建 endpoint。
注意: 如果要删除 endpoint,请执行以下命令:
DROP ENDPOINT PlayerRecord_EP然后它将被删除。
(B) WSDL 文件创建
在本例中,WSDL 可以在以下位置查看:https://:8000/PlayerName?wsdl
部分输出如下:
我们将 WSDL 文件保存在硬盘上。为此,在 IE 浏览器中,右键单击 -> 查看源代码 -> 文件 -> 另存为…。将文件另存为 PlayerList.wsdl,保存在硬盘上的任意方便的位置。
(C) Web 服务任务配置及使用 Web 服务任务调用 Web 服务
我们将按照以下步骤满足要求:
步骤 1: 打开 BIDS 并创建一个新的 Integration Services 项目。在 Control Flow 设计器中,从工具箱中拖放一个 Web 服务任务。
步骤 2: 双击 Web 服务任务以打开 Web 服务任务编辑器。
步骤 3: 从 General 列表项中,我们将提供以下信息:
- HttpConnection
- WSDL file
- OverwriteWSDLFile
(a) 配置 HttpConnection 字段
在 HttpConnection 中,让我们单击空白区域,然后从下拉列表中选择 <New Connection…>。
在 Http Connection Manager Editor 中选择 "Server" 选项卡,并进行以下设置:
- 输入 Server URL(在本例中为 https://:8000/PlayerName?wsdl)
- 输入凭据,即用户名、密码、域(可选)
最后单击 OK。
(b) 配置 WSDL 文件字段
在 WSDL File 字段中,让我们从保存的位置选择 PlayerList.wsdl 文件。
(c) 配置 OverwriteWSDLFile 字段
此字段需要设置为 TRUE。
完成此操作后,单击 Download WSDL 按钮。如果一切顺利,您将收到下载成功的消息。
步骤 4: 在 Input 选项卡提供的输入屏幕中,让我们为以下项输入信息:
(i) Service
(ii) Corresponding Web method
步骤 5: 在 Output 选项卡提供的输出屏幕中,我们将 OutputType 设置为文件连接,然后指定文件名。
最后,单击 OK 按钮。
步骤 6: 生成并运行包。
现在打开 Outputfile.txt,内容(部分)如下:
这表明它正在工作。
结论
在本文中,我们学习了如何创建 HTTP Endpoint、配置 Web 服务任务以及最终通过 Web 服务任务调用 Web 服务。Web 服务也可以使用脚本组件进行调用,这部分内容我们可以在其他文章中讨论。希望对您有帮助!
感谢阅读本文。