Calling a secure webservice in SSIS through script task

折月煮酒 提交于 2019-12-12 14:12:55

问题


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.


回答1:


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.




回答2:


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/



来源:https://stackoverflow.com/questions/37292239/calling-a-secure-webservice-in-ssis-through-script-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!