473,766 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stream does not support concurrent IO read or write operations

Hi,

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

Here is the message from immediate window

?myResp.GetResp onseStream()
{System.Net.Con nectStream}
System.IO.Strea m: {System.Net.Con nectStream}
AlreadyAborted: 777777
BufferedData: <undefined value>
BufferOnly: false
BytesLeftToWrit e: 0
CallInProgress: false
CanRead: true
CanSeek: false
CanWrite: false
Connection: {System.Net.Con nection}
DataAvailable: true
drainingBuffer: {Length=1024}
Eof: false
ErrorInStream: false
IgnoreSocketWri te: false
Length: <error: an exception of type:
{System.NotSupp ortedException} occurred>
m_BufferedData: <undefined value>
m_BufferOnly: false
m_BytesLeftToWr ite: 0
m_CallNesting: 0
m_Chunked: false
m_ChunkedNeedCR LFRead: false
m_ChunkEofRecvd : false
m_ChunkSize: 0
m_ChunkTerminat or: {Length=5}
m_Connection: {System.Net.Con nection}
m_CRLF: {Length=2}
m_DoneCalled: 0
m_Draining: false
m_ErrorExceptio n: { }
m_ErrorResponse Status: false
m_IgnoreSocketW rite: false
m_MaxDrainBytes : 65536
m_NeedCallDone: true
m_ReadBuffer: {Length=4096}
m_ReadBufferSiz e: 2825
m_ReadBytes: 16436
m_ReadCallbackD elegate: {System.AsyncCa llback}
m_ReadChunkedCa llbackDelegate: {System.Threadi ng.WaitCallback }
m_ReadOffset: 1271
m_Request: <undefined value>
m_ShutDown: 0
m_TempBuffer: {Length=2}
m_Timeout: 300000
m_TotalBytesToW rite: 0
m_WriteBufferEn able: false
m_WriteCallback Delegate: {System.AsyncCa llback}
m_WriteDoneEven t: <undefined value>
m_WriteStream: false
Position: <error: an exception of type:
{System.NotSupp ortedException} occurred>
s_UnloadInProgr ess: false
StreamContentLe ngth: 16436
Timeout: 300000
TotalBytesToWri te: 0
WriteChunked: false

Below is the code:

public WebResponse MakeRequestGetR esponse(string url, IDictionary
postData, string userName, string password, int timeoutSeconds, string
method, string proxyUrl, bool useProxy)
{
try
{
#region set up HttpWebRequest and associated objects
HttpWebRequest myReq;
myReq = (HttpWebRequest )WebRequest.Cre ate(url);

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

myReq.Credentia ls = new NetworkCredenti al(myUserName,
password, myDomain);
myReq.Timeout = timeoutSeconds * 1000;
myReq.CookieCon tainer = _cookieContaine r;
myReq.AllowWrit eStreamBufferin g = true;
myReq.AllowAuto Redirect = 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.Credent ials = myReq.Credentia ls;
myReq.Proxy = myProxy;
}

ServicePointMan ager.Certificat ePolicy = new
AcceptAllCertif icatePolicy();
StringBuilder postDataString = null;
#endregion

#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.GetRespon se();

case "POST":
myReq.Method = "POST";
postDataString = new StringBuilder() ;
foreach (string myKey in postData.Keys)
{
if (postDataString .Length == 0)
postDataString. Append(myKey + "=" +
(string)postDat a[myKey]);
else
postDataString. Append("&" + myKey + "=" +
(string)postDat a[myKey]);
}

ASCIIEncoding encoding = new ASCIIEncoding() ;
byte[] byteArray =
encoding.GetByt es(postDataStri ng.ToString());
myReq.ContentTy pe = "applicatio n/x-www-form-urlencoded";
myReq.ContentLe ngth = byteArray.Lengt h;
LogHelpers.LogM essage(0,"unabl e to set length");
_cookieContaine r =new CookieContainer ();
using (MemoryStream myStream = (MemoryStream)
(myReq.GetReque stStream()))
{
myStream.Write( byteArray, 0,byteArray.Len gth);
myStream.Flush( );
}
try
{

// Read the content.

HttpWebResponse myResp =
(HttpWebRespons e)myReq.GetResp onse();
// Display the status.
Debug.WriteLine (((HttpWebRespo nse)
(myResp)).Statu sDescription);
//retain the cookies
foreach (Cookie cook in myResp.Cookies)
{
_cookieContaine r.Add(cook);
}
//Check out the HTML
StreamReader sr = new
StreamReader(my Resp.GetRespons eStream());
Console.WriteLi ne(sr.ReadToEnd ());

//myWriter.Close( );
return myResp;
}
catch (Exception e)
{
throw WebRequestor.Ge tWrappedExcepti on
("Unable to open HTTP response stream.", e);
//e.Message.ToStr ing();
}

default:

throw new ReportProviderP ermanentErrorEx ception(
"Unsupporte d HTTP method: " + method);
}
}

catch (ReportProvider Exception e) {throw e;}
catch (Exception e)
{
throw new ReportProviderP ermanentErrorEx ception("Unhand led
error.", e);
}
//return myStream;
#endregion
}

/// <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
request.</param>
/// <param name="userName" >username for NetworkCredenti al</param>
/// <param name="password" >password for NetworkCredenti al</param>
/// <param name="timeoutSe conds">timeout for the HTTP request</
param>
/// <param name="method">H TTP method. Must be "GET", "HEAD" or
"POST"</param>
/// <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 </
param>
/// <returns>respon se from the web server in the form of a string</
returns>
public string MakeRequestGetR esponseString(s tring url, IDictionary
postData, string userName, string password, int timeoutSeconds, string
method, string proxyUrl, bool useProxy)

{
System.Text.Str ingBuilder mySb;

using(WebRespon se myResp = MakeRequestGetR esponse(url, postData,
userName, password, timeoutSeconds, method, proxyUrl, useProxy))

{
try
{
using (Stream myRespStream = myResp.GetRespo nseStream())
{
using (StreamReader myStream = new StreamReader(my RespStream))
{
try
{
mySb = new System.Text.Str ingBuilder();
string myLine;

while ((myLine = myStream.ReadLi ne()) != null)
{
if (myLine.Length 0)
mySb.Append(myL ine);
}
}

catch (Exception e)
{
throw WebRequestor.Ge tWrappedExcepti on("Unable to read
response string.", e);
}
}
}
}
catch (Exception e)
{
throw WebRequestor.Ge tWrappedExcepti on("Unable to get response
stream.", e);
}
}

return mySb.ToString() ;
}
}
}

Also sometimes i also get this exception:

NASD.ReportProv ider.Crd.Test.C rdProviderTest. DebugInProc :
System.Applicat ionException : service returned TemporaryError on
Begin. Error messasge:
NASD.ReportProv ider.ReportProv iderTemporaryEr rorException: Unable to
get response stream. --->
NASD.ReportProv ider.ReportProv iderTemporaryEr rorException: Unable to
read response string. ---System.IO.IOExc eption: Unable to read data
from the transport connection. --->
System.Net.Sock ets.SocketExcep tion: An existing connection was
forcibly closed by the remote host
at System.Net.Sock ets.Socket.Begi nReceive(Byte[] buffer, Int32
offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback,
Object state)
at System.Net.Sock ets.NetworkStre am.BeginRead(By te[] buffer, Int32
offset, Int32 size, AsyncCallback callback, Object state)
--- End of inner exception stack trace ---

thanks,
Vishnu
Dec 14 '07 #1
0 2887

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3887
by: Amey Samant | last post by:
hi all i was trying to read an integer from keyboard with DataInputStream can someone explain the behaviour of the following code ???? <code> DataInputStream dis=new DataInputStream(System.in); DataOutputStream dout = new DataOutputStream(System.out); a=dis.readInt(); System.out.println("Using system.out a = "+a);
6
52266
by: Hardy Wang | last post by:
Hi all: The Stream object from WebRequest.GetResponseStream() is non-seekable. How can I convert this stream to a byte array? For ordinary Stream (seekable), I can use StreamObject.Read(myByteArray, 0, myLength) --
8
17338
by: Scott | last post by:
Hi guys, If I try to call read(), readline(), readtoend() and there is nothing to read (from a never ending loop for example) the program seems to continue but it exits the loop for no apparent reason. We also can't check the stream for the length, as the network stream doesn't support seek operations
7
3153
by: simonrigby_uk | last post by:
Hi all, Sorry if this is the incorrect group but I couldn't see anything directly relevant. Can someone confirm for me what happens when two network streams are sent to an application at the same time. My scenario is a small server application that listens on a particular TCP port. I am sending streams of data to it via a client app. Inside
2
1395
by: Loane Sharp | last post by:
Hi there I'm downloading data from a remote server to my local disk using Stream.Read() and Stream.Write() (as previously suggested by Ken Tucker in this group). By and large the download and local write operations occur successfully, but frequently the data transfer is "intermittent", ie. sometimes the connection to the server becomes idle and no data transfer occurs over the wire. The code eventually resumes execution as if all the...
4
6724
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my code ?? thank you Pedro Leite From Portugal ------------------------------------
9
3701
by: anachronic_individual | last post by:
Hi all, Is there a standard library function to insert an array of characters at a particular point in a text stream without overwriting the existing content, such that the following data in appropriately moved further down? From a cursory search of the libc documentation I can't find such a function. Will I have to write it myself? Thanks.
7
13382
by: semedao | last post by:
Hi, I am using cryptostream on both sides on tcp connection that pass data. I am also use asyc socket , so , the data that recieved in the callback method not always have the length of the buffer I sent. for ex I want to send 10000 bytes I can get it in 10 times of 1000 bytes each. so , I need to know when I complete the receiving , I want to write inside cryptostream and check the position compare it to the length I already know I...
2
5348
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi Is there any way to Read an INIFile from a string or Stream instead of a physical file ??? I want to read the INIFile into a string then store in a db but when I read the string from the db or save string to the db I don't want to have to copy the string to a file to use the WritePrivateProfileString and GetPrivateProfileString. Is there a way around this instead of writing my own class to operate on a string or stream ???
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.