简体   繁体   中英

Calling a secure webservice in SSIS through script task

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.

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.

Add a service reference, in the solution explorer. This will allow you to reference the web service in code and explore through the object browser. I usually go to the WSDL through a browser first to explore the properties and methods.

If script task is not an absolute requirement you can try the web service task: https://www.mssqltips.com/sqlservertip/3272/example-using-web-services-with-sql-server-integration-services/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM