?
Solved

Web service - unclosed connections

Posted on 2012-03-13
5
Medium Priority
?
787 Views
Last Modified: 2012-03-14
I've been asked to take a look at a problem we're having with web service connections not being closed.

My understanding is that after 4 minutes the connections are closed by the server?

I guess the problem is that we are running out of available connections?

I am looking for some advice on some common things to look for in the C# source that may be causing the connections not to close.

How does garbage collection and web services work normally?

Is there a way to ensure that the socket connection closes immediately after the web service call is finished?


I was shown on the server what the unclosed connections look like:
netstat -bn


 TCP    127.0.0.1:2808         127.0.0.1:28002        ESTABLISHED     2360
 [avscc.exe]


 TCP    10.1.10.27:5070        8.26.196.251:80        CLOSE_WAIT      1648
 [VCTray.exe]

 TCP    127.0.0.1:4548         127.0.0.1:7031         CLOSE_WAIT      2632
 [jusched.exe]



///////////// these connections are not getting closed ///////////////////////////
 TCP    10.1.10.27:4887        10.1.10.22:135         TIME_WAIT       0
 TCP    10.1.10.27:4888        10.1.10.22:1025        TIME_WAIT       0
 TCP    10.1.10.27:4993        10.1.20.2:443          TIME_WAIT       0
 TCP    10.1.10.27:4994        10.1.20.2:443          TIME_WAIT       0
 TCP    10.1.10.27:4995        10.1.20.2:443          TIME_WAIT       0
 TCP    10.1.10.27:4996        10.1.20.2:443          TIME_WAIT       0
 TCP    10.1.10.27:4997        10.1.20.2:443          TIME_WAIT       0

Open in new window




From a scalability perspective, some of the people I have spoken to have suggested that this problem has only recently begun to happen because the web service is getting called more often.  So, bugs that you might get away with start to come to the surface that were not evident before.  They think that is what we are experiencing.
0
Comment
Question by:Tom Knowlton
[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
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:lojk
ID: 37718120
I just posted a comment in another question that should answer this question for you quite nicely.. :-)

http://www.experts-exchange.com/Programming/Languages/.NET/Q_27630876.html
0
 
LVL 9

Accepted Solution

by:
lojk earned 2000 total points
ID: 37718139
Not closing wcf and xml-ws calls is a very common problem, only exacerbated by the fact it is so easy to create the connection (I.e. A new client instance/connection each time) and these days we are all so used to garbage collection tidying up for us that we forget to do the right thing.

I try and reuse the connection where possible if likely to be frequently used (e.g data proxying ) but sometimes it is clearer to drop it and create a new one when you know the calls will be infrequent and inconsistent and/or you are sympathetic to or actually the guy running the web server hosting the service.
0
 
LVL 5

Author Closing Comment

by:Tom Knowlton
ID: 37720336
Thank you.

In case I can't find the sample code, can you show me in a code snippet how to close the connection?
0
 
LVL 9

Expert Comment

by:lojk
ID: 37720672
Just checked on my wcf4 service if you browse to the .svc url you get the sample..

here is the output of that page though, warts and all...

---------------------------------------------


svcDataSync Service


You have created a service.

To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:



svcutil.exe http://localhost/BytesStore/svcDataSync.svc?wsdl

This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:


C#

class Test
{
    static void Main()
    {
        IsvcDataSyncClient client = new IsvcDataSyncClient();

        // Use the 'client' variable to call operations on the service.

        // Always close the client.
        client.Close();
    }
}



Visual Basic

Class Test
    Shared Sub Main()
        Dim client As IsvcDataSyncClient = New IsvcDataSyncClient()
        ' Use the 'client' variable to call operations on the service.

        ' Always close the client.
        client.Close()
    End Sub
End Class
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 37720715
Perfect...yes...I eventually found this.


Please see my new question:

http://www.experts-exchange.com/Programming/Languages/.NET/Q_27631964.html
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

800 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