Solved

Add timeout to a webservice response

Posted on 2014-10-08
10
135 Views
Last Modified: 2014-11-24
I have a function in my VB.NET application which consumes a webservice. That webservice is a bit inconsistent and does load. That is, if i go to it's wsdl URL when it is down, it would not load for 2 minutes and then return "Not available".

So in my function I want to give the web service 30 seconds to respond. If it does not then i would like to go to the next step. Can I do that?

Sub Bind()
GetWebService()
getOtherData()
End Sub

Sub getWebservice()
Dim webservResponse As String
Dim oXmlResponse As New System.Xml.XmlDocument

'Add timeout for the entire getWebservice function (or) just the line below.

  webservResponse = webservice.getinvoicexyz(<username>, <password>, billnumber)

End Sub
0
Comment
Question by:Angel02
  • 4
  • 4
  • 2
10 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40369105
Did you "attach" to this web service by going to "Add Service Reference"?
0
 

Author Comment

by:Angel02
ID: 40369151
yes. I did that. I actually went to "Advanced" and added as a web reference.
"getinvoicexyz" is a method in the webservice.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40369167
OK, was there a bunch of stuff added to your app.config/web.config?
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40382342
You need to use a thread or a backgroundworker and kill it after a set time limit if it does not come back.
0
 

Author Comment

by:Angel02
ID: 40392736
@kaufmed
Not really. Only username and password for the webservice.

@CodeCruiser
I tried something like this right before calling the webserive but not sure how this works

             Dim aTimer As Timer

            ' Create a timer
            aTimer = New System.Timers.Timer(5000)
           
            AddHandler aTimer.Elapsed, AddressOf callbk
            aTimer.Enabled = True
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 40394184
Looks like there is an easier way. There is a timeout property on the client itself which you can use

http://msdn.microsoft.com/en-us/library/system.web.services.protocols.webclientprotocol.timeout.aspx
0
 

Author Comment

by:Angel02
ID: 40413374
This is what I did in my method. I don't have a way to check this as the webservice hasn't timed out since I made this change. So hopefully this is right.

Sub getWebservice()
      Dim webservResponse As String
      Dim oXmlResponse As New System.Xml.XmlDocument
      Dim webservice As New MyLiveWebService.mywebservMethod

      webservice.Timeout = 5000
        webservResponse = webservice.getinvoicexyz(<username>, <password>, billnumber)

End Sub
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40417143
Did you test it against a dummy webservice which takes longer than 5 seconds to return result?
0
 

Author Comment

by:Angel02
ID: 40417815
How can I find a dummy webservice? I know it has to be valid so what is the best way?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 40453680
You can create a dummy webservice yourself.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question