tags:

views:

363

answers:

1

I have a WCF service that is essentially running in a loop and outputting files to a directory.

I am getting this interesting error that I managed to find with tracing enabled

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"&gt;
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"&gt;
<EventID>524340</EventID>
<Type>3</Type>
<SubType Name="Error">0</SubType>
<Level>2</Level>
<TimeCreated SystemTime="2010-03-06T14:06:35.3593750Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{f133e2e7-d86a-4ce3-8e4a-427e502817d0}" />
<Execution ProcessName="w3wp" ProcessID="2036" ThreadID="5" />
<Channel />
<Computer>SLOW</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error">
<TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.ServiceOperationExceptionOnReply.aspx&lt;/TraceIdentifier&gt;
<Description>Replying to an operation threw a exception.</Description>
<AppDomain>/LM/W3SVC/1/Root/ISDS-1-129123577914375000</AppDomain>
<Source>System.ServiceModel.Dispatcher.ImmutableDispatchRuntime/38732823</Source>
<Exception>
<ExceptionType>System.Web.HttpException, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</ExceptionType>
<Message>Server cannot set status after HTTP headers have been sent.</Message>
<StackTrace>
at System.Web.HttpResponse.set_StatusCode(Int32 value)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.SetStatusCode(Int32 statusCode)
at System.ServiceModel.Channels.HttpOutput.HostedRequestHttpOutput.PrepareHttpSend(Message message)
at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
at System.ServiceModel.Channels.HttpRequestContext.OnReply(Message message, TimeSpan timeout)
at System.ServiceModel.Activation.HostedHttpContext.OnReply(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestContextBase.Reply(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestContextBase.Reply(Message message)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc&amp; rpc)
</StackTrace>
<ExceptionString>System.Web.HttpException: Server cannot set status after HTTP headers have been sent.
   at System.Web.HttpResponse.set_StatusCode(Int32 value)
   at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.SetStatusCode(Int32 statusCode)
   at System.ServiceModel.Channels.HttpOutput.HostedRequestHttpOutput.PrepareHttpSend(Message message)
   at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
   at System.ServiceModel.Channels.HttpRequestContext.OnReply(Message message, TimeSpan timeout)
   at System.ServiceModel.Activation.HostedHttpContext.OnReply(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.RequestContextBase.Reply(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.RequestContextBase.Reply(Message message)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.Reply(MessageRpc&amp; rpc)</ExceptionString>
</Exception>
</TraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>

I have no idea what is causing this issue, any ideas where to begin trying to fix this?

Thanks in advance.

+1  A: 

When the service sends the response it starts by building and then sending the response in packets. The first thing to be sent back to the client is the http headers, once the headers have been sent on the network, it is not possible to change them.

You probably have some code that runs too late in the process.

Shiraz Bhaiji