9

I have got a MyServiceBase class which inherits from ServiceBase. Inside MyService I Have got a ServiceHost for my WCF-service, whic has only one method with IsOneWay=true property. I used this code to initialize it:

host = new ServiceHost(typeof(MyService));
host.Opened += new EventHandler(host_Opened);
host.Closed += new EventHandler(host_Closed);
host.Faulted += new EventHandler(host_Faulted);
host.UnknownMessageReceived += new EventHandler<UnknownMessageReceivedEventArgs>(host_UnknownMessageReceived);
host.Open();

Sometimes host raises Faulted event, but EventArgs in *host_Faulted* method are always empty, so I cannot find out the reason of it. Please help. Thanks in regard.

Alekstim
  • 452
  • 1
  • 8
  • 19
  • I have tried to use pseudovariables (http://msdn.microsoft.com/en-us/library/ms164891.aspx) but I didn't see $exception variable in locals window – Alekstim Dec 10 '12 at 12:13
  • Don't forget to leave a parameter-less constructor in your Host implementation – oo_dev Jun 25 '18 at 12:02

2 Answers2

4

This link might prove usefull for better ways of WCF Fault handling and debugging:

How do I prevent a WCF service from enter a faulted state?

So instead of answering your specific question, i am recommending a better way of achieving your requirement.

Community
  • 1
  • 1
c0D3l0g1c
  • 3,020
  • 5
  • 33
  • 71
  • 5
    This is helpful but did not answer the actual question. How does one get the exception stack that caused the service to fault? – BeanFlicker Nov 17 '16 at 14:10
0

I met this problem today. By enabling WCF Tracing, it helps, but did not give me the reason. After lots of debugging work, I found the real reason is: Client which consumes WCF services crashed. Since the client is a wrapped Windows Service, and its status is still 'running'.

So my suggestion is: try/catch all the code blocks in your client application.

Elliot Chen
  • 378
  • 2
  • 9