troubleshooting Question

When to close the web service client connection in a scaled environment

Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America asked on
Web Languages and StandardsWeb Development.NET ProgrammingASP.NET
24 Comments1 Solution888 ViewsLast Modified:
I see the client for the web service getting created:

          fileWebService = new SPFWebService.File.Service1();

but I don't see it getting closed.

When is it appropriate to close the connection?

I am in an environment where this web service is being used by lots of different console applications.  There is never a time where the web service will not be in use, but there will be lots of connections left open at any one time that are not being closed, we think, because the Close( ) command is never getting called.  Can I close the client connection without affecting the other apps that are using the same service?


namespace MetaSource.SPF.Storage
    public class SPFStorageSPF : ISPFStorage
        private string basePath;
        private SPFWebService.File.Service1 fileWebService;

        public SPFStorageSPF(string Site, string UserName, string Password, string BasePath)
            basePath = BasePath;

            fileWebService = new SPFWebService.File.Service1();
            fileWebService.Url = Site;
            fileWebService.Credentials = new NetworkCredential(UserName, Password);
            fileWebService.Timeout = 600000;

        #region ISPFStorage Members

        public bool Put(
            out string FilePath,
            ref string FileName, 
            string FileExtension, 
            bool Image,
            string ClientCode,
            int ProjectID,
            int DocumentID, 
            int FileID, 
            byte[] FileData)
            string errorMessage;

            return fileWebService.Put(
                ref FileName, 
                out FilePath, out errorMessage);            

        public bool Get(string FilePath, string FileName, int DocumentID, out byte[] FileData)
            return fileWebService.Get(Path.Combine(basePath, FilePath), FileName, out FileData);

        public List<ActiveSource.Formats.File> GetMultiple(List<ActiveSource.Formats.File> Files)
          return fileWebService.GetMultiple(Files.BinarySerialize().Compress())

        public bool Delete(string FilePath, string FileName)
            if (File.Exists(Path.Combine(FilePath, FileName)))
                    File.Delete(Path.Combine(FilePath, FileName));

                    return true;
                catch (Exception)
                    return false;
            return false;


In a separate program I called a web service method 10 times and then closed it, but the connections remain open:

  TCP     CLOSE_WAIT      3508
  TCP        CLOSE_WAIT      3032
  TCP        ESTABLISHED     4700
  TCP        ESTABLISHED     4700
  TCP        ESTABLISHED     4700
  TCP        ESTABLISHED     4700
  TCP    [::1]:59202            [::1]:65119            TIME_WAIT       0
  TCP    [::1]:59203            [::1]:65119            TIME_WAIT       0
  TCP    [::1]:59204            [::1]:65119            TIME_WAIT       0
  TCP    [::1]:59205            [::1]:65119            TIME_WAIT       0
  TCP    [::1]:59206            [::1]:65119            TIME_WAIT       0
  TCP    [::1]:59207            [::1]:65119            TIME_WAIT       0
  TCP    [::1]:59208            [::1]:65119            TIME_WAIT       0
  TCP    [::1]:59209            [::1]:65119            TIME_WAIT       0
  TCP    [::1]:59210            [::1]:65119            TIME_WAIT       0
  TCP    [::1]:65119            [::1]:59201            TIME_WAIT       0

The lines like this one:

  TCP    [::1]:65119            [::1]:59201            TIME_WAIT       0

are what I see AFTER the program has stopped running.

So how do I close the open connection?
.Net and Infrastructure Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 24 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 24 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros