Script Task Help!!
Hello,
When trying to execute the following script it gives me error :
Unhandled Exception: System.ArgumentException: Stream was not writable.
at System.IO.StreamWriter..ctor(Stream stream, Encoding encoding, Int32 buffe
rSize)
at System.IO.StreamWriter..ctor(Stream stream, Encoding encoding)
at System.Xml.XmlTextWriter..ctor(Stream w, Encoding encoding)
at System.Xml.XmlDocument.Save(Stream outStream)
at ConsoleApplication4.Program.Main()
C Sharp Script:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;
using System.Xml;
using System.IO;
namespace ConsoleApplication4
{
public class Program
{
public static bool CertificateValidator(
object sender,
System.Security.Cryptography.X509Certificates.X509Certificate certificate,
System.Security.Cryptography.X509Certificates.X509Chain chain,
System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
}
public static void Main()
{
System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CertificateValidator);
HttpWebRequest request = CreateWebRequest();
//WebClient service = new WebClient();
XmlDocument soapEnvelopeXml = new XmlDocument();
soapEnvelopeXml.LoadXml(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<authorize xmlns=""https://anywhere.com/api/"">
<accountid>1234</accountid>
<key>asdfasfbasdf</key>
</authorize>
</soap:Body>
</soap:Envelope>");
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
stream.Close();
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
Console.WriteLine(soapResult);
rd.Close();
}
}
soapEnvelopeXml.LoadXml(
@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<getEventList xmlns=""https://anywhere.com/api/""
/>
</soap:Body>
</soap:Envelope>");
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
Console.WriteLine(soapResult);
}
}
}
/// Create a soap webrequest to [Url]
public static HttpWebRequest CreateWebRequest()
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"https://anywhere.com/api/");
webRequest.Headers.Add(@"SOAP:Action");
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
}
}
Can anybody please point me what might be the issue ?
Thanks,
April 18th, 2011 11:31am
Is this script running successfully in BIDS and fails after you deploy your package?
Looking at it you experimented first by doing a Console app and then moved into the Script Task.
Besides, if you are trying to consume a webservice you may be better off using the
WebSericve task.
Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
April 18th, 2011 11:36am
Thanks for the response. Yes, first I am experimenting doing a console app and will later move it to Script task. What I am trying to do is:
1. Pass the SOAP request and get the response.
<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<authorize xmlns=""https://anywhere.com/api/"">
<accountid>1234</accountid>
<key>asdfasfbasdf</key>
</authorize>
</soap:Body>
</soap:Envelope>
2. Then pass the 2nd SOAP request and get the response.
<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<getEventList xmlns=""https://anywhere.com/api/""
/>
</soap:Body>
</soap:Envelope>
The error is on 2nd
System.Xml.XmlDocument.Save(Stream outStream)
Any response would be highly appreciated.
Thanks,
April 18th, 2011 11:45am
Why not to use the WebService Task?So the code has no authorize
segment. Is that OK?
Besides, the post is not SSIS related at this time. I suggest you code it out first properly then post here in case you have a SSIS related issue.Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
April 18th, 2011 11:56am