Disabling Keep-Alive

M

Mantorok

Hi

ASP.Net v2.0

I'm referencing a web-service from an ASP.Net web-site. Occasionally, I get
an intermittent error when accessing the web-service:
System.Web.HttpUnhandledException: Exception of type
'System.Web.HttpUnhandledException' was thrown. --->
System.Net.WebException: The underlying connection was closed: An unexpected
error occurred on a receive. ---> System.IO.IOException: Unable to read data
from the transport connection: An existing connection was forcibly closed by
the remote host. ---> System.Net.Sockets.SocketException: An existing
connection was forcibly closed by the remote hostI've been advised to try
disabling Keep-Alive.How can this be achieved?ThanksKev
 
S

Steven Cheng[MSFT]

Hi Mantorok,

As for the webservice proxy, if you're using ASP.NET web site application
to generate the proxy, you do not have the underlying auto-generated code
as it will be dynamically generated and compiled at runtime. And you will
not be able to access the internal webrequest object this way. You can
consider manually use wsdl.exe to create the web proxy or use a separate
class library project to create the webservice proxy. Thus, you can access
the autogenerated source code of the webservice proxy and do some
customization on the code. The webservice proxy class has a
"GetWebRequest" protect method that can help you get the underlying
webrequest object, you can try converting the webrequest to HttpWebRequest
and configure the KeepAlive property. e.g.

==========================

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.o
rg/HelloWorld", RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string HelloWorld() {
WebRequest request = this.GetWebRequest(this.Url);
HttpWebRequest httpreq = request as HttpWebRequest;

httpreq.KeepAlive = false;
..............
======================

BTW, for the problem you met, since it occurs occasionally, I think you can
still do some further check to see whether it may be caused by some
server-side service unavailable or exception.

If there is anything else you wonder, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mantorok

Steven Cheng said:
Hi Mantorok,

As for the webservice proxy, if you're using ASP.NET web site application
to generate the proxy, you do not have the underlying auto-generated code
as it will be dynamically generated and compiled at runtime. And you will
not be able to access the internal webrequest object this way. You can
consider manually use wsdl.exe to create the web proxy or use a separate
class library project to create the webservice proxy. Thus, you can access
the autogenerated source code of the webservice proxy and do some
customization on the code. The webservice proxy class has a
"GetWebRequest" protect method that can help you get the underlying
webrequest object, you can try converting the webrequest to HttpWebRequest
and configure the KeepAlive property. e.g.

==========================

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.o
rg/HelloWorld", RequestNamespace="http://tempuri.org/",
ResponseNamespace="http://tempuri.org/",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public string HelloWorld() {
WebRequest request = this.GetWebRequest(this.Url);
HttpWebRequest httpreq = request as HttpWebRequest;

httpreq.KeepAlive = false;
.............
======================

Thanks very much for this, I've generated the proxy and overriden the
method, I will see if this makes a difference.
BTW, for the problem you met, since it occurs occasionally, I think you
can
still do some further check to see whether it may be caused by some
server-side service unavailable or exception.

What else would I be able to check? I would be very grateful if you have any
further suggestions, I always find diagnosing problems like these a bit of a
nightmare.

Thanks
Kev
 
S

Steven Cheng[MSFT]

Thanks for your reply Kev,

Yes, I agree that such scenario is quite hard to troubleshoot as the
network issue is not quite stable and reproducable. Currently, I still
suggest you check whether the server-side service will ocassionally
break(due to some internal issue or exception) that make the webservice
call/connection be ended unexpectedly.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Kev,

Have you got any progress on this issue? And have you tried monitoring the
server-side service to see any exceptional behavior that may related to the
client-side problem? If there is anything else we can help, please feel
free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

Ken Wessel

Hi Steve,

I have tried using your code suggestion to set Keep-Alive for a web service "client side"

Uri uri = new Uri(this.Url);
WebRequest request = this.GetWebRequest(uri);
HttpWebRequest httpreq = request as HttpWebRequest;
httpreq.KeepAlive = false;

My client class was generated by wsdl.exe

Unfortunately the WebRequest object "request" has always been null on the return from this.GetWebRequest.

I tried using the this.GetWebRequest in the constructor and a client web service operation call which of course are both inside of the wsdl.exe code (both times the "request" came back null)

Do you know where the this.GetWebRequest(uri) call can be used to get an valid instance of WebRequest in a web service client object?

Thanks,
Ken Wessel


EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
M

Mantorok

Hi Steven

The application appears to be behaving itself now, I successfully disabled
Keep-Alive and that seems to have made a big difference.

Thanks
Kev
 
M

Mantorok

WebRequest request = this.GetWebRequest(uri);

Shouldn't this be - base.GetWebRequest(uri);

Kev
 
S

Steven Cheng[MSFT]

Hi Kev,

Thanks for your followup. Glad that you've made progress through the change
and also thanks for sharing the result to us.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top