Home All Groups Group Topic Archive Search About

setting a timeout for web service response

Author
24 Jun 2009 8:42 PM
cj2
I have a windows app that calls a web service.  If the web service
requires more than 20 seconds to reply I would like to timeout waiting
for a response from it and proceed on with processing.  Is there any way
to set a timeout?

It's a windows form application and the web service is legacy asp.net.

Author
24 Jun 2009 9:25 PM
Mr. Arnold
"cj2" <cj2@nospam.nospam> wrote in message
news:OZV0NxQ9JHA.4560@TK2MSFTNGP05.phx.gbl...
>I have a windows app that calls a web service.  If the web service requires
>more than 20 seconds to reply I would like to timeout waiting for a
>response from it and proceed on with processing.  Is there any way to set a
>timeout?
>
> It's a windows form application and the web service is legacy asp.net.
>

Before the call to the Webservice on the client side, it would be
Webservice.Timeout = 20.

I have not used VB in a long time, but it's something like this in C#.

var client = new Webservice;
client.Timeout = 20;
client.WebServiceMethod();

One can also set Timeout = -1,  which means it never times out or infinity
and is good in debug mode and debugging a Web Service, that would normally
timeout during debug single stepping in Web service code.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4186 (20090624) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
Author
24 Jun 2009 10:53 PM
Mike
This requires that you either issue the HTTP request either
asynchronously or as a background thread (which can be more complex to
setup).

The socket API select() function helps prepare an async I/O request
with timeout values provided.

Generally, a normal sync connect is can he used  because thats either
going to be A) blocked or B) not server on the port is listening.

When blocked, typically, the response is fast.  When there is no
listening server, then the default timeout is around 30 seconds.

So if you want a 20 second time,  then you need to do use select()
before with the the connect command and loop/wait for the response.

Same with idea with write (sending the request), by that point you are
probably ok to just use a sync write, but you can use select here as well.

But if you think the remote server could take long,  then definitely
need to use an async read request (select() + read()) otherwise it
will only return when A) it finishes or B) the socket is broken
(connection drop).

--



cj2 wrote:

Show quoteHide quote
> I have a windows app that calls a web service.  If the web service
> requires more than 20 seconds to reply I would like to timeout waiting
> for a response from it and proceed on with processing.  Is there any way
> to set a timeout?
>
> It's a windows form application and the web service is legacy asp.net.
>
Author
24 Jun 2009 11:12 PM
Mike
cj2,

Here is .net socket class example using select()

http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.select.aspx

These had SendAsync() ReceiveAsync() which allow you to use VB.NET
events.  There is also a TCPClient class layer with SendAsync() and
ReadAsync() with events too.  I never used these, but they might use
select with threads.

Should be enough to explore it.

---

Mike wrote:

Show quoteHide quote
> This requires that you either issue the HTTP request either
> asynchronously or as a background thread (which can be more complex to
> setup).
>
> The socket API select() function helps prepare an async I/O request with
> timeout values provided.
>
> Generally, a normal sync connect is can he used  because thats either
> going to be A) blocked or B) not server on the port is listening.
>
> When blocked, typically, the response is fast.  When there is no
> listening server, then the default timeout is around 30 seconds.
>
> So if you want a 20 second time,  then you need to do use select()
> before with the the connect command and loop/wait for the response.
>
> Same with idea with write (sending the request), by that point you are
> probably ok to just use a sync write, but you can use select here as well.
>
> But if you think the remote server could take long,  then definitely
> need to use an async read request (select() + read()) otherwise it will
> only return when A) it finishes or B) the socket is broken (connection
> drop).
>
> --
>
>
>
> cj2 wrote:
>
>> I have a windows app that calls a web service.  If the web service
>> requires more than 20 seconds to reply I would like to timeout waiting
>> for a response from it and proceed on with processing.  Is there any
>> way to set a timeout?
>>
>> It's a windows form application and the web service is legacy asp.net.
>>
>
Author
25 Jun 2009 12:26 PM
Jie Wang [MSFT]
Hi cj2,

Yes, there is a way to set the timeout. But the approach differs from the
legacy SoapHttpClientProtocol client and the WCF client.

I'm going to explain both ways.

If you're using the SoapHttpClientProtocol client (in your project, the
reference to the Web Service is under the *Web References* folder):

You can just set the timeout value via the Timeout property.

For example:

Dim svc As New localhost.Service1 ' <- this is my web service reference

svc.Timeout = 5000 ' <- timeout after 5 seconds
MsgBox(svc.HelloWorld()) ' call the HelloWorld method on the service.

Just like Mr. Arnold said, but the Timeout value unit is milliseconds, not
seconds.

If the web service took more than 5 seconds to return the result, a
WebException will be raised on your windows application side with a message
"The operation has timed out".

Setting the Timeout property to Timeout.Infinite indicates that the request
does not time out. Even though an XML Web service client can set the
Timeout property to not time out, the Web server can still cause the
request to time out on the server side.

For more information, please refer to:
http://msdn.microsoft.com/en-us/library/system.web.services.protocols.webcli
entprotocol.timeout.aspx

***************

If you're using the WCF client (in your project, the reference to the Web
Service is under the *Service References* folder):

You can config the timeout in the app.config, where you can find a <binding
... /> section, there is a sendTimeout attribute indicating the timeout
value. The default timeout value is 1 minute.

For more information, please refer to:
http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding
.aspx

***************

Also, you can config the timeout on the Web Service side (server side) by
configuring <httpRuntime ... executionTimeout />.

For more information, please refer to:
http://msdn.microsoft.com/en-us/library/e1f13641.aspx

Hope these information helps.

If you need further assistance, please kindly let me know.

Best regards,

Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd***@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days 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. 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/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Author
26 Jun 2009 9:19 PM
cj2
Thanks.  That's what I wanted to know.

Jie Wang [MSFT] wrote:
Show quoteHide quote
> Hi cj2,
>
> Yes, there is a way to set the timeout. But the approach differs from the
> legacy SoapHttpClientProtocol client and the WCF client.
>
> I'm going to explain both ways.
>
> If you're using the SoapHttpClientProtocol client (in your project, the
> reference to the Web Service is under the *Web References* folder):
>
> You can just set the timeout value via the Timeout property.
>
> For example:
>
> Dim svc As New localhost.Service1 ' <- this is my web service reference
>
> svc.Timeout = 5000 ' <- timeout after 5 seconds
> MsgBox(svc.HelloWorld()) ' call the HelloWorld method on the service.
>
> Just like Mr. Arnold said, but the Timeout value unit is milliseconds, not
> seconds.
>
> If the web service took more than 5 seconds to return the result, a
> WebException will be raised on your windows application side with a message
> "The operation has timed out".
>
> Setting the Timeout property to Timeout.Infinite indicates that the request
> does not time out. Even though an XML Web service client can set the
> Timeout property to not time out, the Web server can still cause the
> request to time out on the server side.
>
> For more information, please refer to:
> http://msdn.microsoft.com/en-us/library/system.web.services.protocols.webcli
> entprotocol.timeout.aspx
>
> ***************
>
> If you're using the WCF client (in your project, the reference to the Web
> Service is under the *Service References* folder):
>
> You can config the timeout in the app.config, where you can find a <binding
> .. /> section, there is a sendTimeout attribute indicating the timeout
> value. The default timeout value is 1 minute.
>
> For more information, please refer to:
> http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding
> .aspx
>
> ***************
>
> Also, you can config the timeout on the Web Service side (server side) by
> configuring <httpRuntime ... executionTimeout />.
>
> For more information, please refer to:
> http://msdn.microsoft.com/en-us/library/e1f13641.aspx
>
> Hope these information helps.
>
> If you need further assistance, please kindly let me know.
>
> Best regards,
>
> Jie Wang
>
> Microsoft Online Community Support
>
> Delighting our customers is our #1 priority. We welcome your comments and
> suggestions about how we can improve the support we provide to you. Please
> feel free to let my manager know what you think of the level of service
> provided. You can send feedback directly to my manager at:
> msd***@microsoft.com.
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
>
> Note: MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 2 business days 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. 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/en-us/subscriptions/aa948874.aspx
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>