By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,028 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,028 IT Pros & Developers. It's quick & easy.

Stream does not support concurrent IO read or write operations

P: n/a

Am trying to post the data over https and am getting error in
httpwebresponse.getResponseStream.Please help me to get rid of this

Here is the message from immediate window

System.IO.Stream: {System.Net.ConnectStream}
AlreadyAborted: 777777
BufferedData: <undefined value>
BufferOnly: false
BytesLeftToWrite: 0
CallInProgress: false
CanRead: true
CanSeek: false
CanWrite: false
Connection: {System.Net.Connection}
DataAvailable: true
drainingBuffer: {Length=1024}
Eof: false
ErrorInStream: false
IgnoreSocketWrite: false
Length: <error: an exception of type:
{System.NotSupportedException} occurred>
m_BufferedData: <undefined value>
m_BufferOnly: false
m_BytesLeftToWrite: 0
m_CallNesting: 0
m_Chunked: false
m_ChunkedNeedCRLFRead: false
m_ChunkEofRecvd: false
m_ChunkSize: 0
m_ChunkTerminator: {Length=5}
m_Connection: {System.Net.Connection}
m_CRLF: {Length=2}
m_DoneCalled: 0
m_Draining: false
m_ErrorException: { }
m_ErrorResponseStatus: false
m_IgnoreSocketWrite: false
m_MaxDrainBytes: 65536
m_NeedCallDone: true
m_ReadBuffer: {Length=4096}
m_ReadBufferSize: 2825
m_ReadBytes: 16436
m_ReadCallbackDelegate: {System.AsyncCallback}
m_ReadChunkedCallbackDelegate: {System.Threading.WaitCallback}
m_ReadOffset: 1271
m_Request: <undefined value>
m_ShutDown: 0
m_TempBuffer: {Length=2}
m_Timeout: 300000
m_TotalBytesToWrite: 0
m_WriteBufferEnable: false
m_WriteCallbackDelegate: {System.AsyncCallback}
m_WriteDoneEvent: <undefined value>
m_WriteStream: false
Position: <error: an exception of type:
{System.NotSupportedException} occurred>
s_UnloadInProgress: false
StreamContentLength: 16436
Timeout: 300000
TotalBytesToWrite: 0
WriteChunked: false

Below is the code:

public WebResponse MakeRequestGetResponse(string url, IDictionary
postData, string userName, string password, int timeoutSeconds, string
method, string proxyUrl, bool useProxy)
#region set up HttpWebRequest and associated objects
HttpWebRequest myReq;
myReq = (HttpWebRequest)WebRequest.Create(url);

//break off any domain part of the user name
string[] userNameParse = userName.Split('\\');
string myUserName =
string myDomain = userNameParse[0];

myReq.Credentials = new NetworkCredential(myUserName,
password, myDomain);
myReq.Timeout = timeoutSeconds * 1000;
myReq.CookieContainer = _cookieContainer;
myReq.AllowWriteStreamBuffering = true;
myReq.AllowAutoRedirect = true;
// Set Proxy information useProxy is false for all
non DEV environment
// Currently we only need proxy for DEV
if (useProxy)
WebProxy myProxy = new WebProxy();
Uri newUri = new Uri(proxyUrl);
myProxy.Address = newUri;
myProxy.Credentials = myReq.Credentials;
myReq.Proxy = myProxy;

ServicePointManager.CertificatePolicy = new
StringBuilder postDataString = null;

#region stream POST or GET to HTTP server and synchronously
open and return the response stream

switch (method)
case "HEAD":
case "GET":

myReq.Method = method;
return myReq.GetResponse();

case "POST":
myReq.Method = "POST";
postDataString = new StringBuilder();
foreach (string myKey in postData.Keys)
if (postDataString.Length == 0)
postDataString.Append(myKey + "=" +
postDataString.Append("&" + myKey + "=" +

ASCIIEncoding encoding = new ASCIIEncoding();
byte[] byteArray =
myReq.ContentType = "application/x-www-form-urlencoded";
myReq.ContentLength = byteArray.Length;
LogHelpers.LogMessage(0,"unable to set length");
_cookieContainer =new CookieContainer();
using (MemoryStream myStream = (MemoryStream)
myStream.Write(byteArray, 0,byteArray.Length);

// Read the content.

HttpWebResponse myResp =
// Display the status.
//retain the cookies
foreach (Cookie cook in myResp.Cookies)
//Check out the HTML
StreamReader sr = new

return myResp;
catch (Exception e)
throw WebRequestor.GetWrappedException
("Unable to open HTTP response stream.", e);


throw new ReportProviderPermanentErrorException(
"Unsupported HTTP method: " + method);

catch (ReportProviderException e) {throw e;}
catch (Exception e)
throw new ReportProviderPermanentErrorException("Unhandled
error.", e);
//return myStream;

/// <summary>
/// Makes an HTTP request to the URL, passing post parameters as
defined by postData,
/// returning a String response.
/// </summary>
/// <param name="url">URL of the request</param>
/// <param name="postData">string of parameters to post by name
and value. If null,
/// then the request is a GET request; otherwise it is a POST
/// <param name="userName">username for NetworkCredential</param>
/// <param name="password">password for NetworkCredential</param>
/// <param name="timeoutSeconds">timeout for the HTTP request</
/// <param name="method">HTTP method. Must be "GET", "HEAD" or
/// <param name="proxyUrl">Url for proxy server if one is needed
or empty string</param>
/// <param name="useProxy">True if you need to use proxy server </
/// <returns>response from the web server in the form of a string</
public string MakeRequestGetResponseString(string url, IDictionary
postData, string userName, string password, int timeoutSeconds, string
method, string proxyUrl, bool useProxy)

System.Text.StringBuilder mySb;

using(WebResponse myResp = MakeRequestGetResponse(url, postData,
userName, password, timeoutSeconds,method, proxyUrl, useProxy))

using (Stream myRespStream = myResp.GetResponseStream())
using (StreamReader myStream = new StreamReader(myRespStream))
mySb = new System.Text.StringBuilder();
string myLine;

while ((myLine = myStream.ReadLine()) != null)
if (myLine.Length 0)

catch (Exception e)
throw WebRequestor.GetWrappedException("Unable to read
response string.", e);
catch (Exception e)
throw WebRequestor.GetWrappedException("Unable to get response
stream.", e);

return mySb.ToString();

Also sometimes i also get this exception:

NASD.ReportProvider.Crd.Test.CrdProviderTest.Debug InProc :
System.ApplicationException : service returned TemporaryError on
Begin. Error messasge:
NASD.ReportProvider.ReportProviderTemporaryErrorEx ception: Unable to
get response stream. --->
NASD.ReportProvider.ReportProviderTemporaryErrorEx ception: Unable to
read response string. ---System.IO.IOException: Unable to read data
from the transport connection. --->
System.Net.Sockets.SocketException: An existing connection was
forcibly closed by the remote host
at System.Net.Sockets.Socket.BeginReceive(Byte[] buffer, Int32
offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback,
Object state)
at System.Net.Sockets.NetworkStream.BeginRead(Byte[] buffer, Int32
offset, Int32 size, AsyncCallback callback, Object state)
--- End of inner exception stack trace ---

Dec 14 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.