Background

As we know, SSIS (SQL Server Integration Service) is a data migration software used to extract, transform, and load the data. I am not going to explain what SSIS is and what its features are, but yes, this article illustrates the purpose of SSIS with Web Service. It’s all about how SSIS can use Web Service to perform certain operations, like updating the database table based on Service response or process the data, etc.

Not only Web Service but SSIS can consume the following services as well:

These are the different services provided by Microsoft .NET technology. I will explain how to consume these services through SSIS package in my next article.

Let’s say we have one Web Service running in IIS and it exposes the ProcessData() method. It does some business functionality internally and sends the details to a third party service. It provides the reference number to the client. (Refer the below screen.)

SQL Server Integration Service
More about Web Service

It’s an XML service and runs on HTTP & HTTPS protocol. It accepts the XML request and provides the response in XML format.

Solution

To consume the Web Service into the SSIS package, first, create the SSIS application. You should have SSDT (SQL Service Data Tools) installed on your system. I have used SSDT 2015 in my sample application.

Follow the below steps.

  1. Create package (package.dtsx) inside the SSIS project.
  2. Drag the script task from SSIS toolbox on "Package Design" screen (refer the below screen).

    SQL Server Integration Service
  1. Double click on "Script Task".
  2. Click on "Edit Script".

    SQL Server Integration Service

  3. It will open the VstaProjects where you can write the C# custom code.
  4. Go to the Solution Explorer.

    SQL Server Integration Service

  5. Right click on Reference.
  6. Give the Web Service URL and add into the project (refer the below screen).

    SQL Server Integration Service
  1. Follow the below code. Here, I am passing the transactionID and amount to the ProcessData().

    1. #region Namespaces
    2. using System;
    3. using System.Data;
    4. using Microsoft.SqlServer.Dts.Runtime;
    5. using System.Windows.Forms;
    6. #endregion
    7. namespace ST_c02ad868b1314c3895bebfedd71e7fbf
    8. {
    9. /// <summary>
    10. /// ScriptMain is the entry point class of the script. Do not change the name, attributes,
    11. /// or parent of this class.
    12. /// </summary>
    13. [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    14. public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    15. {
    16. /// <summary>
    17. /// This method is called when this script task executes in the control flow.
    18. /// Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
    19. /// To open Help, press F1.
    20. /// </summary>
    21. public void Main()
    22. {
    23. // the below detail can be pulled from database and send to the service.
    24. long transactionID = 110011;
    25. decimal amount = 500.0m;
    26. ServiceManager.DemoService demoService = new ServiceManager.DemoService();
    27. try
    28. {
    29. var result = demoService.ProcessData(transactionID, amount);
    30. //based on result or status you can update the required table.
    31. //TODO
    32. Dts.TaskResult = (int)ScriptResults.Success;
    33. }
    34. catch (Exception ex)
    35. {
    36. Dts.TaskResult = (int)ScriptResults.Failure;
    37. }
    38. }
    39. #region ScriptResults declaration
    40. /// <summary>
    41. /// This enum provides a convenient shorthand within the scope of this class for setting the
    42. /// result of the script.
    43. ///
    44. /// This code was generated automatically.
    45. /// </summary>
    46. enum ScriptResults
    47. {
    48. Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
    49. Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    50. };
    51. #endregion
    52. }
    53. }
  1. When you debug the SSIS package, you get the response from Web Service (refer the below screenshot).

    SQL Server Integration Service

Conclusion

SSIS provides the features by using a script component to consume the Web Service. And, it can be achieved by writing the custom code in SSIS.