代码之家  ›  专栏  ›  技术社区  ›  JL. Hans Passant

IIS 6中的WCF:发送HTTP标头后,服务器无法设置状态

  •  1
  • JL. Hans Passant  · 技术社区  · 14 年前

    我有一个WCF服务,它基本上是在循环中运行的,并将文件输出到一个目录。

    我得到了这个有趣的错误,我设法找到与跟踪启用

    <E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
    <System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
    <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</TraceIdentifier>
    <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>
    

    我不知道是什么导致了这个问题,有没有想法从哪里开始尝试解决这个问题?

    1 回复  |  直到 14 年前
        1
  •  1
  •   Shiraz Bhaiji    14 年前

    当服务发送响应时,它首先构建响应,然后以数据包的形式发送响应。首先要发送回客户机的是http头,一旦这些头在网络上被发送,就不可能更改它们。

    您可能有一些代码在这个过程中运行得太晚了。