Hi,
I've written a C# console application to call a RESTful HTTP web service per below:
class Program { static void Main(string[] args) { string URL = "https://sapiqa.overstock.com/api"; string APIMethod = "GetOrders2"; string MerchantKey = "OurMerchKey"; string AuthenticationKey = "OurAuthKey"; string GetOrders2Response; WebRequest wrq = WebRequest.Create("https://sapiqa.overstock.com/api?" + APIMethod + "?MerchantKey=" + MerchantKey + "?AuthenticationKey=" + AuthenticationKey); wrq.Method = "POST"; // Create POST data and convert it to a byte array. Strip out unnecessary text. byte[] byteArray = Encoding.UTF8.GetBytes(URL.Replace(APIMethod, "")); // Set the ContentType property of the WebRequest. wrq.ContentType = "application/x-www-form-urlencoded"; // Set the ContentLength property of the WebRequest. wrq.ContentLength = byteArray.Length; Stream dataStream = wrq.GetRequestStream(); // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); // Get the response. WebResponse response = wrq.GetResponse(); // Display the status. Console.WriteLine(((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); // Display the content. GetOrders2Response = responseFromServer; Console.WriteLine(responseFromServer); // Clean up the streams. reader.Close(); dataStream.Close(); response.Close(); Console.ReadKey(); } }
The solution builds without errors. When I F5 to debug, the console window doesn't stay open and I see no confirmation that the web service was called or the response that was recieved.
How do I keep the console open? What must be done to write the XML response to SQL Server? Ideally, I want to use this as a script component in SSIS but want to start with the basicss first.
Thanks for your help and guidance.