i use a WCF-Service.
It workes fine, and if i use a forbidden IP it shows me a message.
But if i change the ip in my textbox to the right IP it will be again catch the TCP exception, with the OLD IP… The IP-string in the textbox is the corret one and all variables contains the right IP…
The exception:
CommunicationException TCP-Fehler
(10049: Die angeforderte Adresse ist
in diesem Kontext ungültig) beim
Lauschen am
IP-Endpunkt=192.168.178.2:7997.
Should be 192.168.178.25
And after correcting the IP in the textbox and restarting the server i get the same exception with the old IP…
Here is my method:
I create all ressources new in this methode.
Only the ServiceHost host; Variable is stored outside the methode and i tried to set it null before starting or after exception.
Configure 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");
Start host (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;
}
}
}
I have a hunch that there may be some static state associated with the channel runtime infrastructure for HTTP bindings, which maintains details of HTTP listeners keyed by service Uri. If you are not properly tearing down ServiceHost instances which threw on Open, perhaps the old details remain registered in this static state.
What happens in your catch block following the call to
host.Open()? If you are not callinghost.Abort()andhost.Dispose()on the instances which threw on Open, this might be the problem.