2011-02-25

IIS7中的unable to generate a temporary class错误解决办法

Posted in .NET at 11:55 Author:仲远

标签:

在访问IIS7的网站时,可能会遇到Service Unavailable的错误,错误的原因当然可能会有很多种,因此需要使用Just-In-Time Debugger来go into到实际的内部错误。

错误信息
System.ServiceModel.CommunicationException was unhandled
  Message=There was an error in serializing body of message SearchRequest1: ‘Unable to generate a temporary class (result=1).
error CS2001: Source file ‘C:\Windows\TEMP\s0phakvt.0.cs’ could not be found
error CS2008: No inputs specified
‘.  Please see InnerException for more details.
  Source=mscorlib
  StackTrace:
    Server stack trace:
       at System.ServiceModel.Dispatcher.XmlSerializerOperationFormatter.SerializeBody(XmlDictionaryWriter writer, MessageVersion version, String action, MessageDescription messageDescription, Object returnValue, Object[] parameters, Boolean isRequest)
       at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.BodyWriter.WriteBodyContents(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSizeQuota)
       at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
       at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message)
       at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

解决办法:
右键点击C:\Windows\TEMP 目录,选择 properties->security ,添加 MachineName\IIS_IUSRS 账户(将MachineName替换成实际的服务器名称),给予它Read、Write、List等权限。再重新访问这个ASP页面,问题应该能够得到解决。

原因分析:
应该是在你的ASP页面中,调用了别的Web Service/WCF Service,ASP.NET Web Service有时候会在处理WebMethods时使用到C:\Windows\TEMP文件夹,因此需要给IIS的相关账户赋予相应的权限。

本文可以自由转载,转载时请保留全文并注明出处:
转载自仲子说 [ http://www.wangzhongyuan.com/ ]
原文链接:

Leave a Comment

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word