I'm using a simple c# Windows service client of a remote web-service. Everyghing works great, but when I make a data request to the webservice and then I close the client and the factory too, the https connection doesn't close. (I can see it with 'netstat -n' command). Why? Any idea?
This is my code:
BasicHttpBinding binding = new BasicHttpBinding();
binding.CloseTimeout = new TimeSpan(0, 0, 10);
binding.OpenTimeout = new TimeSpan(0, 0, 10);
binding.ReceiveTimeout = new TimeSpan(0, 0, 10);
binding.SendTimeout = new TimeSpan(0, 0, 10);
string address = AppSettings.Instance.address;
if (address.Contains("https"))
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.MaxBufferSize = 2147483647;
binding.MaxBufferPoolSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;
XmlDictionaryReaderQuotas readerQuotas = new XmlDictionaryReaderQuotas();
readerQuotas.MaxStringContentLength = 2147483647;
binding.ReaderQuotas = readerQuotas;
ChannelFactory<NotifierServiceChannel> factory = new ChannelFactory<NotifierServiceChannel>(binding, address);
factory.Closed += Factory_Closed;
factory.Closing += Factory_Closing;
factory.Faulted += Factory_Faulted;
factory.Opened += Factory_Opened;
factory.Opening += Factory_Opening;
foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find<DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
dataContractBehavior.MaxItemsInObjectGraph = 2147483647;
}
factory.Open();
using (NotifierServiceChannel client = factory.CreateChannel())
{
client.Closed += _client_Closed;
client.Closing += _client_Closing;
client.Faulted += _client_Faulted;
client.Opened += _client_Opened;
client.Opening += _client_Opening;
client.UnknownMessageReceived += _client_UnknownMessageReceived;
client.Open(new TimeSpan(0, 0, 10));
GetIdRequest requestId = new GetIdRequest();
GetIdResponse responseId = client.GetIdResponse(requestId);
LogManager.LoggerV("client.State = " + client.State.ToString());
if (client.State == CommunicationState.Faulted)
client.Abort();
else
client.Close();
LogManager.LoggerV("client.State = " + client.State.ToString());
client.Dispose();
LogManager.LoggerV("client.State = " + client.State.ToString());
}
LogManager.LoggerV("factory.State = " + factory.State.ToString());
if (factory.State == CommunicationState.Faulted)
factory.Abort();
else
factory.Close();