Solved

Add timeout to a webservice response

Posted on 2014-10-08
10
137 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
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…

756 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