Solved

Necessary or optional to close a webservice client connection

Posted on 2012-03-13
3
271 Views
Last Modified: 2012-03-14
If I have created a web service client that makes a call to a method exposed by a web service, do I need to perform some sort of close when I am finished using the object?

  ConsoleApplicationTomTest.ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();

            string a = sc.GetData(1);

            Console.WriteLine(a);

            Console.ReadLine();

///////////  sc.CloseClientConnection(  )   ??????????
0
Comment
Question by:Tom Knowlton
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
lojk earned 500 total points
ID: 37718100
Short answer - yes.

If you access the URL for the service in the browser and read the sample there (xml-ws) or follow the instructions for creating a client code block from the wsdl (wcf) you will see the example does indeed close the connection.

if you don't you'll rapidly find that the timeout interval of the client connection at the server side prevents the automatic disposal of the connection in time to free up enough connections and you will hit the limit (partially stipulated by your xmlws/wcf configuration file) and start receiving error messages about connection limits.

Try instantiating a few hundred instances of your connection/test method call and you will see what I mean - always be lean, create as few instances as possible and dispose of them properly and promptly. This goes for all instances of classes not just wcf/xml-ws clients.
0
 
LVL 9

Expert Comment

by:lojk
ID: 37718144
Return cross posted link to related question FYI :-)

http://www.experts-exchange.com/Programming/Languages/.NET/Q_27630729.html
0
 
LVL 5

Author Closing Comment

by:Tom Knowlton
ID: 37720329
Thank you.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 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