E
Elvandar
I've a problem with a WCF application. It has 2 parts:
- a Windows Service which exposes a WCF interface on port 15000, channel
type Net TCP
- a WPF client application which connects to the service.
Here is the example interface of the server:
SERVER
public class Program
{
static void Main (string[] args)
{
ServiceHost myInterface = new ServiceHost (typeof (MyService));
myInterface.Open ();
}
}
public interface IMyService
{
[OperationContract]
bool Login (string Username, string Password);
}
public class MyService : IMyService
{
[OperationBehavior]
public bool Login (string Username, string Password)
{
//...autenticazione...
return true;
}
}
And here is an example of the client side:
App.xaml:
Startup="Application_Startup"
ShutdownMode="OnLastWindowClose"
Exit="Application_Exit"
public partial class App : Application
{
public static MyServiceClient server;
private void Application_Startup (object sender, StartupEventArgs e)
{
server = new MyServiceClient ();
server.Open ();
}
private void Application_Exit (object sender, ExitEventArgs e)
{
server.Close ();
}
}
public partial class LoginWindow : Window
{
public void btnLogin_Click (object sender, RoutedEventArgs e)
{
bool result = App.server.Login (txtUsername.Text,
txtPassword.Password);
if (result)
{
string s = null;
s.Split (' '); // Here an exception is thrown
}
}
}
The problem occurs in a situation like this:
1. Server start (Net TCP channel on port 15000)
2. Client start. It correctly connects to server
3. Login on client
4. After Login() returns with true, the client executes some code and,
due to a bug, it crashes
5. I start a new client. It correctyle connects to server (Open() method
doesn't throw any exception)
6. Try to call Login()
7. The client hangs and then returns with a TimeoutException
8. Must restart server (or at least the WCF ServiceHost)
So, sometimes, after the client crashes, the server must be restarted
because its WCF interface doesn't accept any method call...it seems to
be correctly exposed (both via telnet and opening a new client), but if
I try to call any method, it never arrives to the server side (tested in
debug mode in Visual Studio with breakpoints), it seems the call is
being "lost".
Observing the ServiceHost on the server, it never goes to Faulted state,
no Exception is thrown, nothing. Simply, WCF interface is opened but
calls are lost. And this behaviour isn't predictable, because sometimes
it occurs after just 1 client crash, sometimes the client must crash 4
or 5 times before server "hangs"...
Any idea? Thanks to all, and Merry Christmas!
- a Windows Service which exposes a WCF interface on port 15000, channel
type Net TCP
- a WPF client application which connects to the service.
Here is the example interface of the server:
SERVER
public class Program
{
static void Main (string[] args)
{
ServiceHost myInterface = new ServiceHost (typeof (MyService));
myInterface.Open ();
}
}
public interface IMyService
{
[OperationContract]
bool Login (string Username, string Password);
}
public class MyService : IMyService
{
[OperationBehavior]
public bool Login (string Username, string Password)
{
//...autenticazione...
return true;
}
}
And here is an example of the client side:
App.xaml:
Startup="Application_Startup"
ShutdownMode="OnLastWindowClose"
Exit="Application_Exit"
public partial class App : Application
{
public static MyServiceClient server;
private void Application_Startup (object sender, StartupEventArgs e)
{
server = new MyServiceClient ();
server.Open ();
}
private void Application_Exit (object sender, ExitEventArgs e)
{
server.Close ();
}
}
public partial class LoginWindow : Window
{
public void btnLogin_Click (object sender, RoutedEventArgs e)
{
bool result = App.server.Login (txtUsername.Text,
txtPassword.Password);
if (result)
{
string s = null;
s.Split (' '); // Here an exception is thrown
}
}
}
The problem occurs in a situation like this:
1. Server start (Net TCP channel on port 15000)
2. Client start. It correctly connects to server
3. Login on client
4. After Login() returns with true, the client executes some code and,
due to a bug, it crashes
5. I start a new client. It correctyle connects to server (Open() method
doesn't throw any exception)
6. Try to call Login()
7. The client hangs and then returns with a TimeoutException
8. Must restart server (or at least the WCF ServiceHost)
So, sometimes, after the client crashes, the server must be restarted
because its WCF interface doesn't accept any method call...it seems to
be correctly exposed (both via telnet and opening a new client), but if
I try to call any method, it never arrives to the server side (tested in
debug mode in Visual Studio with breakpoints), it seems the call is
being "lost".
Observing the ServiceHost on the server, it never goes to Faulted state,
no Exception is thrown, nothing. Simply, WCF interface is opened but
calls are lost. And this behaviour isn't predictable, because sometimes
it occurs after just 1 client crash, sometimes the client must crash 4
or 5 times before server "hangs"...
Any idea? Thanks to all, and Merry Christmas!