Hallo J'ai besoin d'une connexion Tcp à un serveur vivant dans backgrond et les applications enverront des données avec cette connexion.J'ai cherché autour et trouvé singlet WCF est affecté à cette tâche voici un extrait de code que je utiliser ci-dessous ma question est que la bonne façon et tout problème peut être avec cela?Maintenez TcpClient Connexion avec WCF
string hostAddress = string.Empty;
try
{
srvHost = new ServiceHost(typeof(ControllerClass));
NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None);
netTcpBinding.Security.Message.ClientCredentialType = MessageCredentialType.None;
netTcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None;
netTcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
srvHost.AddServiceEndpoint(typeof(IControllerContract), netTcpBinding, hostAddress);
srvHost.Credentials.WindowsAuthentication.AllowAnonymousLogons = true;
ServiceThrottlingBehavior serviceThrottlingBehavior = new ServiceThrottlingBehavior();
serviceThrottlingBehavior.MaxConcurrentCalls = 1000;
serviceThrottlingBehavior.MaxConcurrentInstances = 1000;
serviceThrottlingBehavior.MaxConcurrentSessions = 1000;
srvHost.Description.Behaviors.Add(serviceThrottlingBehavior);
srvHost.Open();
}
catch (System.TimeoutException timeoutEx)
{
Thread.Sleep(1000);
ReOpenHostConnection();//initialize again Controller Class
}
catch (Exception ex)
{
Trace.WriteLine(string.Format("cannot start Service Ex:{0}", ex.ToString()), TraceEventType.Error.ToString());
}
//Controller Class Initialize Code Snippet
TcpClient iTcpClient = new TcpClient();
iTcpClient.Connect(serverIP, serverPort);
networkStream = iTcpClient.GetStream();
aSychDataByte = new byte[iTcpClient.ReceiveBufferSize];
networkStream.BeginRead(aSychDataByte, 0, incommTcpClient.ReceiveBufferSize, ReadAsych, null);
Je me connecte à un serveur TCP tiers. Premièrement, je lance une commande de démarrage qui sera active à tout moment et les applications clientes enverront des données sur cette connexion sur un service wcf singleton – dankyy1
Et êtes-vous sûr que votre code utilise cette connexion vous avez démarré manuellement? –
J'ouvre et maintenez la connexion tcp au serveur tiers avec l'objet tcpclient sur les procédures wcf singleton l'objet tcpclient est utilisé. – dankyy1