Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Necessary or optional to close a webservice client connection

Posted on 2012-03-13
3
Medium Priority
?
280 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 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline

877 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