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(
basePath,
ClientCode,
ProjectID.ToString(),
ref FileName,
FileExtension,
Image,
DocumentID,
FileID,
FileData,
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())
.Decompress().BinaryDeserialize<List<ActiveSource.Formats.File>>();
}
public bool Delete(string FilePath, string FileName)
{
if (File.Exists(Path.Combine(FilePath, FileName)))
{
try
{
File.Delete(Path.Combine(FilePath, FileName));
return true;
}
catch (Exception)
{
return false;
}
}
return false;
}
#endregion
}
}
TCP 10.1.30.14:64554 128.241.220.104:80 CLOSE_WAIT 3508
[jusched.exe]
TCP 10.1.30.14:64643 10.1.10.22:3268 CLOSE_WAIT 3032
[OUTLOOK.EXE]
TCP 127.0.0.1:52988 127.0.0.1:52989 ESTABLISHED 4700
[firefox.exe]
TCP 127.0.0.1:52989 127.0.0.1:52988 ESTABLISHED 4700
[firefox.exe]
TCP 127.0.0.1:52990 127.0.0.1:52991 ESTABLISHED 4700
[firefox.exe]
TCP 127.0.0.1:52991 127.0.0.1:52990 ESTABLISHED 4700
[firefox.exe]
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplicationTomTest
{
class Program
{
static void Main(string[] args)
{
ConsoleApplicationTomTest.ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();
OutputToConsole("Remote Address", sc.InnerChannel.RemoteAddress.ToString());
OutputToConsole("Remote Address is Anonymous", sc.InnerChannel.RemoteAddress.IsAnonymous.ToString());
OutputToConsole("Via", sc.InnerChannel.Via.ToString());
sc.InnerChannel.OperationTimeout = TimeSpan.FromSeconds(10);
string a = "";
OutputToConsole(sc.State.ToString());
for (int i = 0; i < 2; i++)
{
a = sc.GetData(1);
OutputToConsole(sc.State.ToString());
OutputToConsole(a);
}
OutputToConsole(sc.State.ToString());
sc.Close();
OutputToConsole(sc.State.ToString());
Console.ReadLine();
}
private static void OutputToConsole(string outputmessage)
{
Console.WriteLine(outputmessage);
}
private static void OutputToConsole(string intro, string outputmessage)
{
Console.WriteLine(intro + ": " + outputmessage);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}
static void Main(string[] args)
{
ConsoleApplicationTomTest.ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();
OutputToConsole("Remote Address", sc.InnerChannel.RemoteAddress.ToString());
OutputToConsole("Remote Address is Anonymous", sc.InnerChannel.RemoteAddress.IsAnonymous.ToString());
OutputToConsole("Via", sc.InnerChannel.Via.ToString());
sc.InnerChannel.OperationTimeout = TimeSpan.FromSeconds(10);
string a = "";
OutputToConsole(sc.State.ToString());
[subtitle] [b] for (int j = 0; j < 5; j++)
{
for (int i = 0; i < 5; i++)
{
a = sc.GetData(1);
OutputToConsole(sc.State.ToString());
OutputToConsole(a);
}
}[/b]
[/subtitle]
OutputToConsole(sc.State.ToString());
sc.Close();
OutputToConsole(sc.State.ToString());
Console.ReadLine();
}
...
...
[firefox.exe]
TCP 127.0.0.1:64640 127.0.0.1:6999 TIME_WAIT 0
TCP 127.0.0.1:64642 127.0.0.1:6999 TIME_WAIT 0
TCP 127.0.0.1:64645 127.0.0.1:6999 TIME_WAIT 0
TCP 127.0.0.1:64650 127.0.0.1:6999 TIME_WAIT 0
TCP 127.0.0.1:64651 127.0.0.1:6999 TIME_WAIT 0
TCP 127.0.0.1:64654 127.0.0.1:6999 TIME_WAIT 0
TCP 127.0.0.1:64666 127.0.0.1:6999 TIME_WAIT 0
//HERE ARE THE ORPHANED SOCKETS ... THE WEBSERVICE CALL IS ALREADY DONE ...NO NEED FOR THESE SOCKETS TO BE OPEN...
TCP [::1]:64680 [::1]:65119 TIME_WAIT 0
TCP [::1]:64681 [::1]:65119 TIME_WAIT 0
TCP [::1]:64682 [::1]:65119 TIME_WAIT 0
TCP [::1]:64683 [::1]:65119 TIME_WAIT 0
TCP [::1]:64684 [::1]:65119 TIME_WAIT 0
TCP [::1]:64685 [::1]:65119 TIME_WAIT 0
TCP [::1]:64686 [::1]:65119 TIME_WAIT 0
TCP [::1]:64687 [::1]:65119 TIME_WAIT 0
TCP [::1]:64688 [::1]:65119 TIME_WAIT 0
TCP [::1]:64689 [::1]:65119 TIME_WAIT 0
TCP [::1]:64691 [::1]:65119 TIME_WAIT 0
TCP [::1]:64692 [::1]:65119 TIME_WAIT 0
TCP [::1]:64693 [::1]:65119 TIME_WAIT 0
TCP [::1]:64694 [::1]:65119 TIME_WAIT 0
TCP [::1]:64695 [::1]:65119 TIME_WAIT 0
TCP [::1]:64696 [::1]:65119 TIME_WAIT 0
TCP [::1]:64697 [::1]:65119 TIME_WAIT 0
TCP [::1]:64698 [::1]:65119 TIME_WAIT 0
TCP [::1]:64699 [::1]:65119 TIME_WAIT 0
TCP [::1]:64700 [::1]:65119 TIME_WAIT 0
TCP [::1]:64701 [::1]:65119 TIME_WAIT 0
TCP [::1]:64702 [::1]:65119 TIME_WAIT 0
TCP [::1]:65119 [::1]:64678 TIME_WAIT 0
TCP [::1]:65119 [::1]:64679 TIME_WAIT 0
TCP [::1]:65119 [::1]:64690 TIME_WAIT 0
TCP [::1]:64781 [::1]:65119 TIME_WAIT 0
TCP [::1]:64782 [::1]:65119 TIME_WAIT 0
TCP [::1]:64783 [::1]:65119 TIME_WAIT 0
TCP [::1]:64784 [::1]:65119 TIME_WAIT 0
TCP [::1]:64785 [::1]:65119 TIME_WAIT 0
TCP [::1]:64786 [::1]:65119 TIME_WAIT 0
TCP [::1]:64787 [::1]:65119 TIME_WAIT 0
TCP [::1]:64788 [::1]:65119 TIME_WAIT 0
TCP [::1]:64789 [::1]:65119 TIME_WAIT 0
TCP [::1]:64790 [::1]:65119 TIME_WAIT 0
TCP [::1]:64791 [::1]:65119 TIME_WAIT 0
TCP [::1]:64792 [::1]:65119 TIME_WAIT 0
TCP [::1]:64793 [::1]:65119 TIME_WAIT 0
TCP [::1]:64794 [::1]:65119 TIME_WAIT 0
TCP [::1]:65119 [::1]:64780 TIME_WAIT 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplicationTomTest
{
class Program
{
static void Main(string[] args)
{
for (int c = 0; c < 3; c++)
{
ConsoleApplicationTomTest.ServiceReference1.Service1Client sc = new ServiceReference1.Service1Client();
OutputToConsole("Test Iteration", c.ToString());
OutputToConsole("Remote Address", sc.InnerChannel.RemoteAddress.ToString());
OutputToConsole("Remote Address is Anonymous", sc.InnerChannel.RemoteAddress.IsAnonymous.ToString());
OutputToConsole("Via", sc.InnerChannel.Via.ToString());
sc.InnerChannel.OperationTimeout = TimeSpan.FromSeconds(10);
string a = "";
OutputToConsole(sc.State.ToString());
for (int i = 0; i < 5; i++)
{
a = sc.GetData(1);
OutputToConsole(sc.State.ToString());
OutputToConsole(a);
}
OutputToConsole(sc.State.ToString());
sc.Close();
OutputToConsole(sc.State.ToString());
Console.ReadLine();
}
}
private static void OutputToConsole(string outputmessage)
{
Console.WriteLine(outputmessage);
}
private static void OutputToConsole(string intro, string outputmessage)
{
Console.WriteLine(intro + ": " + outputmessage);
}
}
}
if you need to be so direct/aggressive with your control of the TCP channels you may have no other choice but to move to a native TCP client/server connection using a normal socket implementation and forgoing all the WCF/IIS fluff.
https://www.experts-exchange.com/questions/27630729/Web-service-unclosed-connections.html
I would recommend creating and disposing the clients promptly as required...
(dont include the declaration in the class or the intialiser in the ctor - rather store the credentials in private variables in the class)
check out the code below..
Note - i have only implemented the put method wrapper in my code example as its hard work writing without the service reference but I'm sure you can follow the path to fill in the gaps..
namespace MetaSource.SPF.Storage
{
  public class SPFStorageSPF// : ISPFStorage
  {
    protected static class Params
    {
      public static string Site;
      public static string UserName;
      public static string Password;
      public static string BasePath;
    }
    public SPFStorageSPF(string site, string userName, string password, string basePath)
    {//ms coding guideline suggest input params should be camel-case
      Params.BasePath = basePath;
      Params.UserName = userName;
      Params.Password = password;
      Params.Site = site; Â
    }
    protected SPFWebService.File.Service
    {
      return CreateClientConnection(600
    }
    protected SPFWebService.File.Service
    {
      SPFWebService.File.Service
      tret.Url =Params. Site;
      tret.Credentials = new NetworkCredential(Params.U
      tret.Timeout = timeOut;
    }
    #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;
      SPFWebService.File.Service
      bool tRet =   fileWebService.Put(
        Params.BasePath ,
        ClientCode,
        ProjectID.ToString(),
        ref FileName,
        FileExtension,
        Image,
        DocumentID,
        FileID,
        FileData,
        out FilePath, out errorMessage);
      fileWebService.Close();
      return tRet;
    }
   Â
    #endregion
  }
}