使用 WCF 服务(由 Silverlight 使用)时,我们经常遇到错误,这些错误没有给我们提供太多的工作:
The service '/ourservice.svc' cannot be activated due to an exception during compilation. The exception message is: Object reference not set to an instance of an object.. ---> System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.Compilation.DiskBuildResultCache.CacheBuildResult(String cacheKey, BuildResult result, Int64 hashCode, DateTime utcStart) at System.Web.Compilation.BuildManager.CacheBuildResultInternal(String cacheKey, BuildResult result, Int64 hashCode, DateTime utcStart) at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
每当我通过浏览器或使用 Silverlight 客户端使用该服务时,该服务都能正常编译/运行。系统的 Silverlight 端报告了这个同样无益的错误:
System.ServiceModel.CommunicationException:
[HttpWebRequest_WebException_RemoteServer]Arguments: NotFound
我设法找到的唯一线索可能是更改 instancing behaviour但我不确定为什么我们需要这样做,而且我也不知道默认值是什么。AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)
任何建议都会很棒
更新
这是另一个症状 - Silverlight 客户端经常将此异常发送到我们的日志记录服务(写入事件日志 + 电子邮件)
There was an error saving the report - The error object contained errors
System.ServiceModel.CommunicationException: [HttpWebRequest_WebException_RemoteServer]
Arguments: NotFound
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.60129.0&File=System.Windows.dll&Key=HttpWebRequest_WebException_RemoteServer ---> System.Net.WebException: [HttpWebRequest_WebException_RemoteServer]
Arguments: NotFound
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.60129.0&File=System.Windows.dll&Key=HttpWebRequest_WebException_RemoteServer ---> System.Net.WebException: [HttpWebRequest_WebException_RemoteServer]
Arguments: NotFound
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.60129.0&File=System.Windows.dll&Key=HttpWebRequest_WebException_RemoteServer
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<EndGetResponse>b__4(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__1(Object sendState)
--- End of inner exception stack trace ---
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
--- End of inner exception stack trace ---
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
at MyNamespaceSilverlight.Core.ReportServiceReference.ReportServiceClient.ReportServiceClientChannel.EndUpdateReport(IAsyncResult result)
at MyNamespaceSilverlight.Core.ReportServiceReference.ReportServiceClient.MyNamespaceSilverlight.Core.ReportServiceReference.IReportService.EndUpdateReport(IAsyncResult result)
at MyNamespaceSilverlight.Core.ReportServiceReference.ReportServiceClient.OnEndUpdateReport(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
最佳答案
服务中是否有任何内容修改了\bin 目录的内容?在 ASP.NET 下托管时,ASP.NET 运行时将监视\bin 目录中的任何更改,并且当看到更改时,它将尝试重新初始化应用程序,以便它获取可能发生的任何更改。
作为服务正常操作的一部分,您不应将任何内容写入\bin 目录。通常这是日志文件被配置为写入\bin 目录而不是它们自己的特定目录的问题。如果由于某种原因无法将日志文件写入应用程序目录根目录之外的某个位置,只需将它们写入\logs 子目录并配置 ASP.NET 以阻止对该目录的所有访问,如下所示:
<location path="logs">
<system.web>
<authorization>
<deny users="*" />
</authorization>
</system.web>
</location>
关于wcf - NotFound 错误和编译失败的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5002386/