J'utilise un service WCF.WCF: problème ServiceHost (adresses en cache?)
Cela fonctionne très bien, et si j'utilise une adresse IP interdite, il me montre un message. Mais si je change l'adresse IP dans ma zone de texte pour la bonne adresse IP, il sera encore attraper l'exception TCP, avec l'IP OLD ... La chaîne IP dans la zone de texte est le corret et toutes les variables contiennent la bonne adresse IP .. .
L'exception:
CommunicationException TCP-Fehler (10049: Die ist angeforderte Adresse dans diesem Kontext ungültig) beim lauschen am IP-Endpunkt = 192.168.178. : 7997.
Doit être 192.168.178. Et après avoir corrigé l'IP dans la zone de texte et de redémarrer le serveur je reçois la même exception avec l'ancien IP ...
Voici ma méthode: Je crée toutes les ressources nouvelles dans ce Methode. Seul l'hôte ServiceHost; La variable est stockée en dehors de la méthode et j'ai essayé de la rendre nulle avant de commencer ou après une exception.
Configurer Host:
private void MenuItemServerStart_Click(object sender, RoutedEventArgs e)
{
**[ omitted ]**
//Define base addresses so all
//endPoints can go under it
Uri tcpAdrs = new Uri("net.tcp://" +
textBoxLocalIP.Text.ToString() + ":" +
textBoxPort.Text.ToString() + "/WPFHost/");
Uri httpAdrs = new Uri("http://" +
textBoxLocalIP.Text.ToString() + ":" +
(int.Parse(textBoxPort.Text.ToString()) + 1).ToString() +
"/WPFHost/");
Uri[] baseAdresses = { tcpAdrs, httpAdrs };
try
{
host = new ServiceHost(typeof(ChatService.ChatService), baseAdresses);
}
catch (TargetInvocationException ex)
{
if (ex.InnerException != null)
{
**[ omitted ]**
}
return;
}
catch (Exception)
{
**[ omitted ]**
}
NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.None, true);
//Updated: to enable file transefer of 64 MB
tcpBinding.MaxBufferPoolSize = (int)67108864;
tcpBinding.MaxBufferSize = 67108864;
tcpBinding.MaxReceivedMessageSize = (int)67108864;
tcpBinding.TransferMode = TransferMode.Buffered;
tcpBinding.ReaderQuotas.MaxArrayLength = 67108864;
tcpBinding.ReaderQuotas.MaxBytesPerRead = 67108864;
tcpBinding.ReaderQuotas.MaxStringContentLength = 67108864;
tcpBinding.MaxConnections = 100;
**[ omitted ]**
host.AddServiceEndpoint(typeof(ChatService.IChatService),
tcpBinding, "tcp");
//Define Metadata endPoint, So we can
//publish information about the service
ServiceMetadataBehavior mBehave =
new ServiceMetadataBehavior();
host.Description.Behaviors.Add(mBehave);
host.AddServiceEndpoint(typeof(IMetadataExchange),
MetadataExchangeBindings.CreateMexTcpBinding(),
"net.tcp://" + textBoxLocalIP.Text.ToString() + ":" +
(int.Parse(textBoxPort.Text.ToString()) - 1).ToString() +
"/WPFHost/mex");
hôte de départ (Exception):
try
{
**host.Open();** **//Exception here !!!**
}
catch (Exception ex)
{
**[ omitted ]**
}
finally
{
if (host.State == CommunicationState.Opened)
{
((StatusBarItem)statusBar1.Items.GetItemAt(0)).Content = "Gestartet";
MenuItemServerStop.IsEnabled = true;
}
}
}
Il y a un * lot * de code ici à lire - ce serait génial si vous pouviez isoler le problème de sorte que vous ne deviez afficher que 5 à 20 lignes de code. Aussi, pourquoi faites-vous 'Text.ToString()'? Le texte est une chaîne. –
Dans le premier bloc de code je fais des trucs de configuration et dans la seconde j'ouvre la connexion hôte. Là, j'ai l'exception. Je sais que c'est beaucoup de code, mais je ne sais pas si j'ai fait une erreur dans la configuration. host.open() lance l'ecxeption, mais l'ip dans le message d'exception est un ancien. Mais je crée toujours un nouvel hôte et d'autres objets aussi. – user437899
@ user437899: Avez-vous débogué après avoir assigné 'host = new ServiceHost' et vérifié si l'adresse IP a bien été configurée? Ou peut-être que l'Uri a rebondi après avoir été assigné avec un champ de zone de texte? –