首页 > 解决方案 > SSIS Web 服务脚本任务 wsdl 文件

问题描述

我正在开发一个 SSIS 包,我们必须通过脚本任务在 SSIS 中调用或使用 Web 服务。我已经浏览了很多链接,但我无法找到确切的解决方案。

我的要求是我已经有一个 WSDL 文件。我们需要使用该 WSDL 文件,我们需要识别该 WSDL 中的方法,并且需要将该 WSDL 中可用的数据写入数据库表。我们如何读取 WSDL 文件以及如何将数据加载到 DB 表中。

提前致谢

标签: web-servicesssiswsdl

解决方案


这可以使用 python 和一个名为Zeep的模块来完成,我添加了一个方法来将该 API 调用的结果插入到后端,但是如果您按原样运行,它应该在您的 WSDL 文件中返回方法调用。在这种情况下,您只需要创建一个接受 varchar 值的表,称为“WSDLMethods”。

import operator
import pypyodbc
from zeep import Client

dbUser = ''
dbPass = ''
mydatabase = ''
myserver = ''

methodlist = []
wsdl = 'https://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?wsdl'
client = Client(wsdl=wsdl)
for service in client.wsdl.services.values():
    print ("service:", service.name)
    for port in service.ports.values():
        operations = sorted(
            port.binding._operations.values(),
            key=operator.attrgetter('name'))
        for operation in operations:
            methodlist.append(operation.name)

#remove duplicates from list
methodlist = list(set(methodlist))

def insertToDB(methodName):
    connection = pypyodbc.connect('Driver={SQL Server};Server='+myserver+';Database=' +str(mydatabase) +';uid='+ str(dbUser)+';pwd=' + str(dbPass)+'')
    cursor = connection.cursor()
    SQLCommand = (" INSERT INTO WSDLMethods VALUES('" + str(methodName) + "')")
    print(SQLCommand)
    cursor.execute(SQLCommand)
    cursor.close()
    connection.commit()
    connection.close()

for method in methodlist:
    #insertToDB(method)
    print(method)

推荐阅读