Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add timeout to a webservice response

Posted on 2014-10-08
10
Medium Priority
?
141 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as high-speed processing of the cloud.

 
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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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