【问题标题】:SSIS Process Task for Powershell script making SOAP call用于进行 SOAP 调用的 Powershell 脚本的 SSIS 进程任务
【发布时间】:2019-09-12 22:49:13
【问题描述】:

在对这个问题进行了长时间的研究之后,我遇到了一些困难。本质上,我正在尝试对公开的 Web 服务(我有 WSDL)进行 SOAP 调用。我能够运行我的 PowerShell 脚本来进行调用并返回 XML 结果。我无法将它连接到 SSIS 并传递要解析的 XML。我已经阅读了解释如何通过 web 服务(我在 webmethod 上收到错误消息)和脚本/流程任务的文章。

目前正在处理调用 PowerShell 脚本以进行 SOAP 调用并检索我可以解析并插入到 SQL 表中的 XML 响应的流程任务

进程/webservice/脚本任务 VB代码(不精通) PowerShell 将响应保存到文件并插入到 SQL 中

#setting TLS to 1.2 as webservice rejects 1.0
[System.Net.ServicePointManager]::SecurityProtocol = 
[System.Net.SecurityProtocolType]::Tls12

#setting URL Endpoint
$uri = "WebserviceURL"

#structuring the request with the infile being the soap action with headers
$post = Invoke-WebRequest -Uri $uri -InFile c:\SOAPREQUESTACTION -ContentType "text/xml" -method post`

预期结果 - SSIS 能够将 XML 响应解析为变量并插入 SQL 表,之后它将在下一次 SOAP 调用时随着属性的变化而更新项目

示例响应

<?xml version='1.0' encoding='UTF-8'?><env:Envelope 
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body> 
<wd:Report_Data xmlns:wd="WEBSERVICEURN">
<wd:Report_Entry>
<wd:Preferred_Name_-_First_Name>Joe</wd:Preferred_Name_-_First_Name>
<wd:Preferred_Name_-_Last_Name>Professional</wd:Preferred_Name_- 
_Last_Name>
<wd:businessTitle>Joe Professional Title</wd:businessTitle>
<wd:Department wd:Descriptor="Joes Professional Department">
</wd:Report_Entry></wd:Report_Data></env:Body></env:Envelope>

【问题讨论】:

  • 你试过只用New-WebServiceProxy
  • 我有,powershell sciprt 工作,更关心在 SSIS 中使用。我能够获得对变量的响应,但不确定如何调用和解析在 SSIS 中使用过的变量
  • 将 XML 响应粘贴到您的问题中。我可以告诉你如何处理那个字符串
  • @KeithL OP 添加了 XML 响应检查一下

标签: xml powershell soap ssis


【解决方案1】:

首先,我必须将您的 XML 清理为:

<?xml version='1.0' encoding='UTF-8'?><env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body> 
<wd:Report_Data xmlns:wd="WEBSERVICEURN">
<wd:Report_Entry>
<wd:Preferred_Name_-_First_Name>Joe</wd:Preferred_Name_-_First_Name>
<wd:Preferred_Name_-_Last_Name>Professional</wd:Preferred_Name_-_Last_Name>
<wd:businessTitle>Joe Professional Title</wd:businessTitle>
<wd:Department wd:Descriptor="Joes Professional Department"/>
</wd:Report_Entry></wd:Report_Data></env:Body></env:Envelope>

我假设它被下载到一个文件中。我将此文件称为 xml.txt

  1. 添加数据流
  2. 在数据流中添加脚本组件(来源)
  3. 将列添加到输出
  4. 编辑脚本
  5. 添加到命名空间
  6. 使用 System.Xml.Serialization;
  7. 使用 System.Collections.Generic;
  8. 将以下代码添加到 CreateOutputRows()

    var xml = System.IO.File.ReadAllBytes(@"D:\temp\xml.txt");
    System.IO.Stream s_xml = new System.IO.MemoryStream(xml);
    
    XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
    var results = (Envelope)serializer.Deserialize(s_xml);
    foreach (var entry in results.Body.Report_Data.Report_Entry)
    {
        Output0Buffer.AddRow();
        Output0Buffer.fname = entry.Preferred_Name__First_Name;
        Output0Buffer.lname = entry.Preferred_Name__Last_Name;
        Output0Buffer.title = entry.BusinessTitle;
        Output0Buffer.dept = entry.Department.Descriptor;
    }
    s_xml.Close();
    
  9. 使用 xml2csharp.com 之类的网站将 xml 转换为类并粘贴以下类:

     [XmlRoot(ElementName = "Department", Namespace = "WEBSERVICEURN")]
     public class Department
     {
          [XmlAttribute(AttributeName = "Descriptor", Namespace = "WEBSERVICEURN")]
          public string Descriptor { get; set; }
     }
    
     [XmlRoot(ElementName = "Report_Entry", Namespace = "WEBSERVICEURN")]
     public class Report_Entry
     {
          [XmlElement(ElementName = "Preferred_Name_-_First_Name", Namespace = "WEBSERVICEURN")]
          public string Preferred_Name__First_Name { get; set; }
          [XmlElement(ElementName = "Preferred_Name_-_Last_Name", Namespace = "WEBSERVICEURN")]
          public string Preferred_Name__Last_Name { get; set; }
          [XmlElement(ElementName = "businessTitle", Namespace = "WEBSERVICEURN")]
          public string BusinessTitle { get; set; }
          [XmlElement(ElementName = "Department", Namespace = "WEBSERVICEURN")]
          public Department Department { get; set; }
     }
    
     [XmlRoot(ElementName = "Report_Data", Namespace = "WEBSERVICEURN")]
     public class Report_Data
     {
           [XmlElement(ElementName = "Report_Entry", Namespace = "WEBSERVICEURN")]
           public List<Report_Entry> Report_Entry { get; set; }
           [XmlAttribute(AttributeName = "wd", Namespace = "http://www.w3.org/2000/xmlns/")]
           public string Wd { get; set; }
      }
    
      [XmlRoot(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
      public class Body
      {
           [XmlElement(ElementName = "Report_Data", Namespace = "WEBSERVICEURN")]
           public Report_Data Report_Data { get; set; }
      }
    
      [XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
      public class Envelope
      {
            [XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
            public Body Body { get; set; }
            [XmlAttribute(AttributeName = "env", Namespace = "http://www.w3.org/2000/xmlns/")]
            public string Env { get; set; }
      }
    
  10. 保存并退出

  11. 您现在可以在数据流中使用您的列来做任何您想做的事情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-28
    • 2017-06-08
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多