473,786 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help !! Problem about HttpWebRequest - GetResponse()

Hi all,

I have problem when I use HttpWebRequest and take long time to call to my
service server. If at that time there are many request comes in
semultaneous, I will get this exception

System.Net.WebE xception: The underlying connection was closed: The request
was canceled. ---> System.IO.IOExc eption: Unable to read data from the
transport connection. ---> System.ObjectDi sposedException : Cannot access a
disposed object named "System.Net.Tls Stream".
Object name: "System.Net.Tls Stream".
at System.Net.Sock ets.NetworkStre am.EndRead(IAsy ncResult asyncResult)
at System.Net.TlsS tream.AsyncRece iveComplete(IAs yncResult result)
--- End of inner exception stack trace ---
at System.Net.TlsS tream.EndRead(I AsyncResult asyncResult)
at System.Net.Conn ection.ReadCall back(IAsyncResu lt asyncResult)
--- End of inner exception stack trace ---
at System.Net.Http WebRequest.Chec kFinalStatus()
at System.Net.Http WebRequest.EndG etResponse(IAsy ncResult asyncResult)
at System.Net.Http WebRequest.GetR esponse()
at MFEC.DealerServ ices.Service.Pa ymentGateway.Ca llPaymentGatewa y(String
serviceName, GeneralParamete rCollection inputParam)
Does anybody know how to solve this problem ?
Nov 19 '05 #1
5 5875
Hi,

The problem is that your proxy is not allowing the webrequest.
Do one thing create a webproxy object with your proxy name and port and
bind it to webrequest like this.

// True is to by pass proxy for local
WebProxy proxy = new WebProxy(name:p ort, true);

// suppose req is HttpWebRequest object
req.Proxy = proxy;

and then user req.getResponse method to get the response.

Regards,
Angrez

Nov 19 '05 #2
Hi singh_angrez,

Thank you for your suggestion. But I can test it in next 2 day after this
weekend. After I try I will report the result again if it can solve my
problem or not
Thank you very much

Jap.
Nov 19 '05 #3
Hi singh_angrez,
Before I try your suggestion. I wanna show you about my code.
And my server architecture is like this

Web server ----httprequest call to --> My service server

Actually, If my service server reponse the result to me in a short time,
everything is ok..no exception. But anytime my service server take long
time to process and send me the result.. at that time if there are many
requests from web server call to my service server, I got that exception
until my service server have a good response.

This is my code now. May be my code is not correct about HttpWebRequest
property.
//==== set ssl connection ==
ServicePointMan ager.Certificat ePolicy = new MyPolicy();

HttpWebRequest objRequest = (HttpWebRequest )WebRequest.Cre ate
(PAYMENTGATEWAY _URL+strParam.T oString());
objRequest.Meth od = "GET";

//==== add new code ==
objRequest.Keep Alive = false;
objRequest.Prot ocolVersion=Htt pVersion.Versio n10;
objRequest.Prox y = System.Net.WebP roxy.GetDefault Proxy(); // I use
default proxy which work well in normal time.
objRequest.Allo wAutoRedirect=t rue;
objRequest.Maxi mumAutomaticRed irections=10;
objRequest.Time out = (int) new TimeSpan(0,0,HT TPTIMEOUT)
..TotalMillisec onds; // ,HTTPTIMEOUT = 300
objRequest.User Agent="Mozilla/3.0 (compatible; My Browser/1.0)";
//==== add new code ==

string str = null;
HttpWebResponse objResponse;
StreamReader sr = null;
try
{
objResponse = (HttpWebRespons e)objRequest.Ge tResponse();

}
catch( Exception e)
{
EventMgmt.Event ExceptionMsg("P ayment Gateway-GetResponse() =>
"+e.ToStrin g(), @"\DataAccess\P GWException");

throw new ServiceExceptio n("PGW001","HOS T_UNREACHABLE", e);
}

try
{
sr = new StreamReader(ob jResponse.GetRe sponseStream()) ;
str = sr.ReadToEnd(). Replace('\n'.To String(),"").Re place('\t'.ToSt ring()
,"").Replace('& '.ToString(),"" );
}
catch( Exception e)
{
EventMgmt.Event ExceptionMsg("P ayment Gateway-ReadResponseStr eam() =>
"+e.ToStrin g(), @"\DataAccess\P GWException");

throw new ServiceExceptio n("PGW003","REA D_STREAM_ERROR" ,e);
}
finally
{
if( sr != null)
sr.Close();
objResponse.Clo se();
}

Thank you,

Jap.
Nov 19 '05 #4
Have you seen this?
http://support.microsoft.com/default...b;en-us;884537

- slightly different scenario, but you might be hitting the same bug.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 22 Apr 2005 10:10:02 GMT, "japslam japslam via
DotNetMonster.c om" <fo***@nospam.D otNetMonster.co m> wrote:
Hi all,

I have problem when I use HttpWebRequest and take long time to call to my
service server. If at that time there are many request comes in
semultaneous , I will get this exception

System.Net.Web Exception: The underlying connection was closed: The request
was canceled. ---> System.IO.IOExc eption: Unable to read data from the
transport connection. ---> System.ObjectDi sposedException : Cannot access a
disposed object named "System.Net.Tls Stream".
Object name: "System.Net.Tls Stream".
at System.Net.Sock ets.NetworkStre am.EndRead(IAsy ncResult asyncResult)
at System.Net.TlsS tream.AsyncRece iveComplete(IAs yncResult result)
--- End of inner exception stack trace ---
at System.Net.TlsS tream.EndRead(I AsyncResult asyncResult)
at System.Net.Conn ection.ReadCall back(IAsyncResu lt asyncResult)
--- End of inner exception stack trace ---
at System.Net.Http WebRequest.Chec kFinalStatus()
at System.Net.Http WebRequest.EndG etResponse(IAsy ncResult asyncResult)
at System.Net.Http WebRequest.GetR esponse()
at MFEC.DealerServ ices.Service.Pa ymentGateway.Ca llPaymentGatewa y(String
serviceName, GeneralParamete rCollection inputParam)
Does anybody know how to solve this problem ?


Nov 19 '05 #5
the default setting for webclient is to only allow two connections to a
remote server. if you calls are slow, and they stack up, you will have
timeout problems. also you could hit your max thread pool sizes.

try upping the number of connections.
(httpRequest.Se rvicePoint.Conn ectionLimit)

-- bruce (sqlwork.com)
"japslam japslam via DotNetMonster.c om" <fo***@DotNetMo nster.com> wrote in
message news:1b******** *************** *******@DotNetM onster.com...
Hi singh_angrez,
Before I try your suggestion. I wanna show you about my code.
And my server architecture is like this

Web server ----httprequest call to --> My service server

Actually, If my service server reponse the result to me in a short time,
everything is ok..no exception. But anytime my service server take long
time to process and send me the result.. at that time if there are many
requests from web server call to my service server, I got that exception
until my service server have a good response.

This is my code now. May be my code is not correct about HttpWebRequest
property.
//==== set ssl connection ==
ServicePointMan ager.Certificat ePolicy = new MyPolicy();

HttpWebRequest objRequest = (HttpWebRequest )WebRequest.Cre ate
(PAYMENTGATEWAY _URL+strParam.T oString());
objRequest.Meth od = "GET";

//==== add new code ==
objRequest.Keep Alive = false;
objRequest.Prot ocolVersion=Htt pVersion.Versio n10;
objRequest.Prox y = System.Net.WebP roxy.GetDefault Proxy(); // I use
default proxy which work well in normal time.
objRequest.Allo wAutoRedirect=t rue;
objRequest.Maxi mumAutomaticRed irections=10;
objRequest.Time out = (int) new TimeSpan(0,0,HT TPTIMEOUT)
.TotalMilliseco nds; // ,HTTPTIMEOUT = 300
objRequest.User Agent="Mozilla/3.0 (compatible; My Browser/1.0)";
//==== add new code ==

string str = null;
HttpWebResponse objResponse;
StreamReader sr = null;
try
{
objResponse = (HttpWebRespons e)objRequest.Ge tResponse();

}
catch( Exception e)
{
EventMgmt.Event ExceptionMsg("P ayment Gateway-GetResponse() =>
"+e.ToStrin g(), @"\DataAccess\P GWException");

throw new ServiceExceptio n("PGW001","HOS T_UNREACHABLE", e);
}

try
{
sr = new StreamReader(ob jResponse.GetRe sponseStream()) ;
str = sr.ReadToEnd(). Replace('\n'.To String(),"").Re place('\t'.ToSt ring()
,"").Replace('& '.ToString(),"" );
}
catch( Exception e)
{
EventMgmt.Event ExceptionMsg("P ayment Gateway-ReadResponseStr eam() =>
"+e.ToStrin g(), @"\DataAccess\P GWException");

throw new ServiceExceptio n("PGW003","REA D_STREAM_ERROR" ,e);
}
finally
{
if( sr != null)
sr.Close();
objResponse.Clo se();
}

Thank you,

Jap.

Nov 19 '05 #6

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

Similar topics

10
19361
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is able to fill that one out just fine. The second form is multipart/form-data. Unfortunately, I haven't been able to fill that out in a way that makes the server happy. I set up a copy of this form at my web site so that I could see exactly what a...
1
1472
by: Raj Chudasama | last post by:
i have a need to load image from URL. the image is really small (gif) and i use the following code. but the code is too slow any1 have any alternative way(S)? here is the url http://phone.avioninc.com/asterisk/wami/graphics/phoneringing.gif -----here is the performance counter out put when i use the code .-------
1
12613
by: Jeff B | last post by:
I'm trying to create a simple screen scraping application and I kept getting a System.Net.WebException thrown back with a message of "The operation has timed-out." At first I thought it was some kind of connectivity issue on the machine. It didn't make sense though, because I can open up a browser on the same machine and easily browse the web. I'm stumped. I looked over my code for any errors and just couldn't find what I was doing...
2
14096
by: Steve Richter | last post by:
I have a page that uses simple HTTP GET to do an ISBN lookup via Amazon.com. The page works when I run it from //localhost. But I have moved it to my godaddy.com shared hoster site, and I get errors on the HttpWebRequest.GetResponse statement. The remote server returned an error: (401) Unauthorized also, when I use the network credentials object in the context of my request, I get this error:
2
4893
by: microdevsolutions | last post by:
Hello I've seen examples to read a file from somewhere into a HttpWebRequest object then write it to a HttpWebResponse object then stream it into a Stream object, very similar to the following code snipet :- ============================================== Uri uri = new Uri("http://www.somewhere/pdf/image1.pdf"); HttpWebRequest httpRequest = null;
5
4872
by: mr.newsgroupguy | last post by:
I am working in C# .NET 1.1. My app has a button on its main form that checks to see if it has access to a file on our server, just an XML file. On our server we are running W2K IIS with a virtual directory, set to Windows Authentication. I am creating an HTTPWebRequest object on the client, and setting its Credentials to CredentialCache.DefaultCredentials. Also, I have tried numerous Timeout settings, but they have not made a...
3
2437
by: Admin.TalkPC | last post by:
Hi people, I have now spent far too much time on this small problem, I am hopefully going to hand it over to you guys that are cleverer than I in this respect. Problem. I need to get all firms in a certain postal code area (say "E1") from the FSA website. I can do this interactively, but I thought I would save time and automate it. Big mistake, I have taken hours investigating an so far failed to get the second search results
1
5687
by: ALA | last post by:
Hi, does anybody know if it is possible to pass the SessionID with a web request by using a cookie so that the invoked page in the same domain can access the session objects of the current user? HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.CookieContainer = new CookieContainer(); HttpCookie sessionCookie = HttpContext.Current.Request.Cookies;
4
5199
by: =?Utf-8?B?SmltIE93ZW4=?= | last post by:
Hi, I've run into a set of errors I don't understand coming back from HttpWebRequest.GetResponse, In one case, null is returned from the request without an Exception and in the other the request does not appear to leave my system yet still returns the 500 error. In the code below, there is a xml-snippet that I use as a test. When I run the test using the snippet, the server on the other side logs and processes the request correctly...
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
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...
0
9960
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...
1
7510
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
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
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.