Hi All,
I need to create a SSIS package that call https site(ssl) and download xml files each day. Right now we have a .net project that create the xml file. But I am asked to create the xml file using SSIS so that we can automate this process.
I do have c# code used in .net project.
What I need is use this code in SSIS script task to call the secured web server and generate a xml file and save it in a local folder.
I don't know much about ASP.NET. Can anyone please tell me how to integrate this code in the scrip task please?
using System; using System.IO; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Xml; using System.Xml.Serialization; namespace DataFetchTest { public class AidapInterface { //Server url for sending out the request. private const string ServerUrl = "https://www.dcf/XmlmyServlet"; private const string UserName = "xyz"; private const string Password = "abc"; private static readonly X509Certificate2 Certificate = new X509Certificate2("myuser_2013.pfx", "BF##20acca"); private static readonly HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(ServerUrl); public void SendRequest() { Request.ClientCertificates.Add(Certificate); Request.Method = "POST"; Request.ContentType = "application/x-www-form-urlencoded"; var myfileFetchTillTime = DateTime.UtcNow.AddHours(-1).ToString("yyyyMMddHHMM"); //const string postData = "uid=" + UserName + "&password=" + Password + "&lastmod=201307021225"; // var postData = "uid=" + UserName + "&password=" + Password + "&lastmod=201307100920";//201307100658 var postData = "uid=" + UserName + "&password=" + Password + "&lastmod=" + myfileFetchTillTime;//201307100658 //uid=uwa&password=abc&lastmod=201307110407 //get the bytes from string var data = Encoding.UTF8.GetBytes(postData); Request.ContentLength = data.Length; using (var requestStream = Request.GetRequestStream()) { requestStream.Write(data, 0, data.Length); requestStream.Close(); } try { //get the response using (var response = Request.GetResponse()) { //var xmlDoc = new XmlDocument(); //xmlDoc.Load(response.GetResponseStream()); var responseStream = response.GetResponseStream(); if (responseStream == null) return; var str = new StreamReader(responseStream); if (str.EndOfStream != true) { //create a structure and populate it with the response. //var serializer = new XmlSerializer(typeof(notamqueryresultset)); //var notamObject = (notamqueryresultset)serializer.Deserialize(str); var result = str.ReadToEnd(); var file = new StreamWriter(Guid.NewGuid()+".xml"); file.WriteLine(result); file.Close(); Console.WriteLine(result); } response.Close(); responseStream.Close(); str.Close(); } } catch (WebException ex) { //for now write the exception message on console Console.WriteLine(ex.Message); } Console.ReadLine(); } } }
Thank you in advance
shamen
shamen