tags:

views:

168

answers:

3

I often use webservice this way

public void CallWebservice()

{

mywebservice web = new mywebservice();

web.call();

}

but sometimes I do this

private mywebservice web;

public Constructor() {

web = new mywebservice();

}

public void CallWebservice() {

web.call();

}

The second approach likes me very much but sometimes it times out and I had to start the application again, the first one I think it brings overhead and it is not very efficient, in fact, sometimes the first call returns a WebException - ConnectFailure (I don't know why).

I found an article (Web Service Woes (A light at the end of the tunnel?)) that exceeds the time out turning the KeepAlive property to false in the overriden function GetWebRequest, here's is the code:

Protected Overrides Function GetWebRequest(ByVal uri As System.Uri) As System.Net.WebRequest

Dim webRequest As Net.HttpWebRequest = CType(MyBase.GetWebRequest(uri), Net.HttpWebRequest)

webRequest.KeepAlive = False

Return webRequest

End Function

The question is, is it possible to extend forever the webservice time out and finally, how do you implement your webservices to handle this issue?

+1  A: 

Hi nmiranda.

The classes generated by Visual Studio for webservices are just proxies with little state so creating them is pretty cheap. I wouldn't worry about memory consumption for them.

If what you are looking for is a way to call the webmethod in one line you can simply do this:

new mywebservice().call()

Cheers

Julio César
A: 

My concern here is the timeout issue to perform a better solution.

nmiranda
A: 

We need to clarify the problem a bit - when you make the call is it the case that you're not expecting a response or do you need to wait for the method to return before the calling code continues?

Assuming we're talking about .NET there are specific provisions for the first case.

Murph

Murph