I am doing a WPF application and it is also a WCF server, the problem I have is that I need the ServiceHost to be open and listen in a port for the clients and accept requests as soon as it starts, but the problem I have is that if I write the code to open the host host.open in the constructor after the function this.InitializeComponent(), it fails with an exception. If I open the host in a button and I press it after the app started, it works without any problems.
Why is that and how can I resolve this issue?
I am utilizing a tcp.net channel,I am hosting it in the application and the exception I receive is about the service already was registered.
The exception on the clients is:
inner exception message :"An existing connection was forcibly closed by the remote host"
error number: 10054
Socket error: System.Net.Sockets.SocketError.ConnectionReset
thanks
Wally
the constructor is:
public Window1()
{
this.InitializeComponent();
starthost();
}
private void starthost()
{
host = new ServiceHost(typeof (Window1),
new Uri[]{ new Uri("net.tcp://localhost:8000") });
host.AddServiceEndpoint(typeof(IGanador), new NetTcpBinding(), "Contador");
host.open(); //it fails with this line here but not in a button
}