Managing webservice connections and/or sessions on clint side


K

Kursat

Hi,

I am employing a webservice in my C# application. I have generated proxy
class for the web service thus I instantiate an object from that class like
it is local, use it and let it garbage collected.
That is all for my side but I don't have any idea about what happens on the
server side. There will be an HTTP connection between client and server. Is
this connection automatically closed by the infrastructure when the
webservice proxy object is finalized? What about the Session on the server
side, when is it closed? Is there anything I should do explicitly with the
webservice proxy object to close http connection and session on server side?

Thanks in advance.
 
Ad

Advertisements

K

Kursat

But the Web Service proxy class inherits non-virtual Dispose method from
"Component" class which doesn't know anything about connection closure.
Right?
 
M

Mr. Arnold

Kursat said:
But the Web Service proxy class inherits non-virtual Dispose method from
"Component" class which doesn't know anything about connection closure.
Right?

I don't use proxy. However, the proxy class is on the client side, and it's
doing the Dispose() of the connection. It's the same thing. If you were not
using a proxy, then you are still responsible for the close of the
connection with a Dispose() at some point in your code that would not be
using a proxy.

If you don't Dispose() the Web service is some fashion in code, then the
Web server itself is going to close the connection on a timeout to release
resources, so the Web server can process other requests of other Web server
clients, and you don't want that.




__________ Information from ESET NOD32 Antivirus, version of virus signature database 4504 (20091013) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
K

Kursat

Hi Arnold,

Thanks for your help but I cant understand. I have a schema file for the web
service and I generated a proxy class by using wsdl.exe. My proxy class
doesn't have any method for connection closing. It just inherits a Dispose
method from "Component" class and I can't use the connection by using this
method. What should I do in this case? You said I am not using proxy class,
what do you for using web services?

Thanks
 
M

Mr. Arnold

Kursat said:
Hi Arnold,

Thanks for your help but I cant understand. I have a schema file for the
web service and I generated a proxy class by using wsdl.exe. My proxy
class doesn't have any method for connection closing. It just inherits a
Dispose method from "Component" class and I can't use the connection by
using this method. What should I do in this case? You said I am not using
proxy class, what do you for using web services?

I don't use a proxy class created by wsdl.exe. I don't know what control
you have over the Web service or your client project, but you can set a Web
Service reference to the Web service over HTTP to a remote Web service
localhost or remote Web service over the Internet.

..NET will take care of everything so you don't have to use wsdl.exe '
generated class, if you use a Web reference in the client project.

http://msdn.microsoft.com/en-us/library/xb5th1ba(VS.80).aspx

I would still do a ws.Dispose() to kill the connection that's being shown to
you in the examples.


It's also being talked about 'Web Service Reference' in a client project on
page 240.

<http://books.google.com/books?id=YC...ge&q=calling a web method from c#.net&f=false>


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4504 (20091013) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
K

Kursat

I know using Web References and the book says generating proxy classes and
adding web references have same results. What I have will be a proxy class
over which I can call webmethods. But the problem is that the class doesn't
implement Dispose() method it just inherit it from the "Component" class
which is useless for connection closing. Does your class implement Dispose()
when you ass web reference? If yes can you send the implementation?

Thanks.
 
Ad

Advertisements

K

Kursat

I added a web reference and it generated the same class. It just inherit
Dispose() from "Component" class.
 
M

milop

Just use "using":

using (MyWebService ws = new MyWebService())
{
ws.DoSomething();
}

At this point the webservice instance has been disposed of.
 
M

Mr. Arnold

milop said:
Just use "using":

using (MyWebService ws = new MyWebService())
{
ws.DoSomething();
}

At this point the webservice instance has been disposed of.

The above is not a good practice, and as a matter of fact, when using a WCF
Web service, there is documentation that specifically indicates not to use
the Using statement on client connection to the WCF Web service.

http://www.devx.com/dotnet/Article/39023

WCF Webservice

var ws = new Webservice();

ws.DoSomething;

ws.Close();

legacy Webservice

var ws = new Webservice();

ws.DoSomething;

ws.Dispose();


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4516 (20091016) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
Ad

Advertisements

M

milop

Well, the bottom line is proper class design, knowledge of managed and
unmanged resources and garbage collection, and disciplined programming
practices.

Although, spcifically calling Dispose() on an object doesn't hurt. Hell, I
even erase arrays when they're no longer going to be used. I don't want to
wait for the GC (I have a C++ background :) )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top