Calling a secure webservice in SSIS through script task

11,807

Add the Service reference under ServiceReferences folder, add the System.ServiceModel under Reference folder (this is to use the EndPointAddress class in the script)

In the Main method, use the following script (high level) to get start with...

 var endPointAddress = new EndpointAddress('http://Server/ServiceName.svc');
 //Put your end point address 
 var basicBinding = new BasicHttpBinding();
 basicBinding.Name = "BasicHttpBinding_IService";
 //this is the port name, you can find it in the WSDL
 ClassServiceClient pay = new ClassServiceClient (basicBinding, endPointAddress);
 //this is the class in which the method exists you want to make a service call 
 IService = pay.YourMethodName();
 XMLDocument xmlOut = new XmlDocument();
 //This is to store return value from your method 
 xmlOut.LoadXml(IService);
 //Load the xmlOut with the return value
 XmlNode xmlNode = xmlOut.SelectSingleNode("ParentElement/ChildElement");
 //Search for your element name where you want to get the value
 string strValue = xmlNode.InnerText;
 //this gives the element value

Next, using DataTable class, load the strValue by creating new rows

DataTable dt = new DataTable();
DataRow dr = dt.NewRow();
dr["ValueToInsertIntoDb"] = strValue;
dr.Rows.Add(dr);

After that assign the dt to an Object Variable.

Dts.Variables["User::Values"].Value = dt;

Next, use another Data flow task, inside that use a Script component and select the variable in ReadOnlyVariables. Inside the script component, you have to loop through the DataTable dataset. Here's the code that should look like

 DataTable dt = (DataTable)Variables.Values
   foreach (DataRow dr in dt.Rows)
   {
     ScriptComponentOutputBuffer.AddRow()
     ScriptComponentOutputBuffer.Column1 = dr["ValueToInsertIntoDb"].ToString();
   }
   //ScriptComponentOutputBuffer.Column1 --You need to manually add this column on output columns of your scriptcomponent

Next, connect the script component to a OLEDB Command or OLE DB Destination and insert the values into the database.

Share:
11,807
Admin
Author by

Admin

Updated on June 29, 2022

Comments

  • Admin
    Admin almost 2 years

    I am working on a SSIS package where we have to call or consume a web service in SSIS through Script task. I have gone through so many links but I am not able to find the exact solution. I am getting so many references, though I am unable to crack it.

    My requirement is I need to call a web service URL through script task which is having a client certificate. After calling this URL we will get a WSDL file from the web service. We need to consume that WSDL file and we need to identify the methods inside this WSDL and need to write the data available in this WSDL to the data base tables. I am not having an idea how can we call that web service URL (with certificate) through script tas, how can we read the WSDL file and how we can load the data into DB table.

  • Admin
    Admin almost 8 years
    Thank you Murthy, i did not understand (IService = cls.YourMethodName(); XMLDocument xmlOut = new XmlDocument(); //This is to store return value from your method) part of the code, please help me to understand
  • MnM
    MnM almost 8 years
    Veeresh, just corrected it. It should be pay.YourMethodName(). That step is calling the method in your web service that returns XML and with the help of XmlDocument, you'll load the returned XML result of method into XmlDocument.
  • Admin
    Admin almost 8 years
    Thanks a lot Murthy, Its working for me, but at this point I could only comsume the http:// webservice (i.e without client certificate), please guide me how can do the same with webservices having client cetificate(https://)