Solved

Add timeout to a webservice response

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Set the FileVersion of a website dll 1 61
asp.net, radiobuttonlist, c# 3 70
FTP recursive download files 5 28
Need to find a web event on the IIS server 4 54
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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

710 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