Solved

Add timeout to a webservice response

Posted on 2014-10-08
10
132 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 74

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 74

Expert Comment

by:käµfm³d 👽
ID: 40369167
OK, was there a bunch of stuff added to your app.config/web.config?
0
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now