[Mono-dev] Exception handling in self-hosted WCF service

Ulrich Hertlein uli at xdt.com.au
Mon Jul 18 04:42:34 EDT 2011


Hi all,

Quoting "Dr. Wolfgang Schwarz | odoscope" <w.schwarz at odoscope.com>:
> I have written a WCF service, running as a console application.
> This service is supposed to be connected to the internet, so it may   
> be exposed to all kind of garbage traffic, or even attacks, and   
> should never crash.
> As it is, the mono framework throws an exception, and the program   
> stops, whenever anything comes in that mono does not understand.
> I can't / don't know how to catch these exceptions in my code.
> Is there a way to make the program run in a stable way?

Not an answer, but a similar problem in a similar setup:

- I have a WCF service that's talking to a Silverlight/Moonlight  
application on localhost
- at some point the WCF service throws an exception (see stacktrace below)
- I have try/catch blocks around everything I can think of but still  
cannot catch this exception and my application dies

Wolfgang, does this look familiar?

Cheers,
/uli

Stacktrace:
Exception Write failure   at System.Net.Sockets.NetworkStream.Write  
(System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in  
<filename unknown>:0
   at System.Net.ResponseStream.InternalWrite (System.Byte[] buffer,  
Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
   at System.Net.ResponseStream.Write (System.Byte[] buffer, Int32  
offset, Int32 count) [0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Channels.Http.HttpRequestContext.InternalReply  
(System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000]  
in <filename unknown>:0
   at System.ServiceModel.Channels.Http.HttpRequestContext.Reply  
(System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000]  
in <filename unknown>:0
   at System.ServiceModel.Dispatcher.MessageProcessingContext.Reply  
(Boolean useTimeout) [0x00000] in <filename unknown>:0
   at System.ServiceModel.Dispatcher.OperationInvokerHandler.Reply  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc, Boolean  
useTimeout) [0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Dispatcher.OperationInvokerHandler.ProcessRequest  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)  
[0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)  
[0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)  
[0x00000] in <filename unknown>:0
   at System.ServiceModel.Dispatcher.HandlersChain.ProcessRequestChain  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)  
[0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Dispatcher.BaseRequestProcessor.ProcessRequest  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)  
[0x00000] in <filename unknown>:0

System.IO.IOException: Write failure --->  
System.ObjectDisposedException: The object was used after being  
disposed.
   at System.Net.Sockets.Socket.Send (System.Byte[] buf, Int32 offset,  
Int32 size, SocketFlags flags) [0x00000] in <filename unknown>:0
   at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer,  
Int32 offset, Int32 size) [0x00000] in <filename unknown>:0

   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Write (System.Byte[] buffer,  
Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
   at System.Net.ResponseStream.InternalWrite (System.Byte[] buffer,  
Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
   at System.Net.ResponseStream.Write (System.Byte[] buffer, Int32  
offset, Int32 count) [0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Channels.Http.HttpRequestContext.InternalReply  
(System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000]  
in <filename unknown>:0
   at System.ServiceModel.Channels.Http.HttpRequestContext.Reply  
(System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000]  
in <filename unknown>:0
   at System.ServiceModel.Dispatcher.MessageProcessingContext.Reply  
(Boolean useTimeout) [0x00000] in <filename unknown>:0
   at System.ServiceModel.Dispatcher.OperationInvokerHandler.Reply  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc, Boolean  
useTimeout) [0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Dispatcher.OperationInvokerHandler.ProcessRequest  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)  
[0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)  
[0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)  
[0x00000] in <filename unknown>:0
   at System.ServiceModel.Dispatcher.HandlersChain.ProcessRequestChain  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)  
[0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Dispatcher.BaseRequestProcessor.ProcessRequest  
(System.ServiceModel.Dispatcher.MessageProcessingContext mrc)  
[0x00000] in <filename unknown>:0

Unhandled Exception: System.InvalidOperationException: Cannot be  
changed after headers are sent.
   at System.Net.HttpListenerResponse.set_ContentType (System.String  
value) [0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Channels.Http.HttpStandaloneResponseInfo.set_ContentType  
(System.String value) [0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Channels.Http.HttpRequestContext.InternalReply  
(System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000]  
in <filename unknown>:0
   at System.ServiceModel.Channels.Http.HttpRequestContext.Reply  
(System.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x00000]  
in <filename unknown>:0
   at System.ServiceModel.Channels.Http.HttpRequestContext.Reply  
(System.ServiceModel.Channels.Message msg) [0x00000] in <filename  
unknown>:0
   at  
System.ServiceModel.Dispatcher.ListenerLoopManager.ProcessRequest  
(IReplyChannel reply, System.ServiceModel.Channels.RequestContext rc)  
[0x00000] in <filename unknown>:0
   at  
System.ServiceModel.Dispatcher.ListenerLoopManager.TryReceiveRequestDone  
(IAsyncResult result) [0x00000] in <filename unknown>:0
Abort trap

-- 
Ulrich Hertlein
Research and Development
XDT Pty Ltd                http://www.xdt.com.au



More information about the Mono-devel-list mailing list