C# WCF服务返回“;请求的服务'';“无法激活”;第一次';从MVC站点访问的

C# WCF服务返回“;请求的服务'';“无法激活”;第一次';从MVC站点访问的,c#,.net,asp.net-mvc-3,wcf,exception-handling,C#,.net,Asp.net Mvc 3,Wcf,Exception Handling,我们有一个由MVC3网站访问的WCF服务(没有安全性) 在开发人员机器上,我们没有任何问题,但当我们的TeamCity安装程序在首次加载MVC3站点并访问WCF服务时构建中心版本并在IIS7下部署它时,服务调用返回消息: System.ServiceModel.ServiceActivationException:请求的服务,'http://localhost:83/ABCStaticData/StaticDataService.svc“无法激活。有关详细信息,请参阅服务器的诊断跟踪日志** 如

我们有一个由MVC3网站访问的WCF服务(没有安全性)

在开发人员机器上,我们没有任何问题,但当我们的TeamCity安装程序在首次加载MVC3站点并访问WCF服务时构建中心版本并在IIS7下部署它时,服务调用返回消息:

System.ServiceModel.ServiceActivationException:请求的服务,'http://localhost:83/ABCStaticData/StaticDataService.svc“无法激活。有关详细信息,请参阅服务器的诊断跟踪日志**

如果我们立即再次访问同一个站点,一切正常

抛出错误时的服务器堆栈跟踪为:

服务器堆栈跟踪:

at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory1 factory, WebException responseException, ChannelBinding channelBinding)
at System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.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) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
at ABC.StaticData.Editor.StaticDataServiceProxy.IStaticDataService.GetAllMarkets()
at ABC.StaticData.Editor.StaticDataServiceProxy.StaticDataServiceClient.GetAllMarkets() in c:\BuildAgent\work\55a3bcc468adcccb\StaticData\ABC.StaticData.Editor\Service References\StaticDataServiceProxy\Reference.cs:line 3195
at ABC.StaticData.Editor.Controllers.MarketsController.<>c__DisplayClass22.<.ctor>b__13() in c:\BuildAgent\work\55a3bcc468adcccb\StaticData\ABC.StaticData.Editor\Controllers\MarketsController.cs:line 263
at ABC.StaticData.Editor.Controllers.MarketsController.Index() in c:\BuildAgent\work\55a3bcc468adcccb\StaticData\ABC.StaticData.Editor\Controllers\MarketsController.cs:line 306
位于System.ServiceModel.Channel.HttpChannelUtilities.ValidateRequestResponse(HttpWebRequest请求、HttpWebResponse响应、HttpChannelFactory1工厂、WebException-responseException、ChannelBinding-ChannelBinding)
位于System.ServiceModel.Channels.HttpChannelFactory1.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度超时)
位于System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan超时)
位于System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时)
在System.ServiceModel.Channels.ServiceChannel.Call(字符串操作、布尔单向、ProxyOperationRuntime操作、对象[]输入、对象[]输出、时间跨度超时
位于System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage方法调用,ProxyOperationRuntime操作)
在[0]处的System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage消息)异常重试:在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg)
at System.Runtime.Remoting.proxy.RealProxy.PrivateInvoke(MessageData&msgData,Int32类型)
在ABC.StaticData.Editor.StaticDataServiceProxy.IStaticDataService.GetAllMarkets()上
在c:\BuildAgent\work\55a3bcc468adcccb\StaticData\ABC.StaticData.Editor.StaticDataServiceProxy.StaticDataServiceClient.GetAllMarkets()中的ABC.StaticData.Editor.StaticDataServiceProxy.StaticDataServiceClient.GetAllMarkets()处,编辑\Service References\StaticDataServiceProxy\Reference.cs:第3195行
在c:\BuildAgent\work\55a3bcc468adcccb\StaticData\ABC.StaticData.Editor.Controllers.MarketsController.c_uu中显示Class22.b_uu13():第263行
在c:\BuildAgent\work\55a3bcc468adcccb\StaticData\ABC.StaticData.Editor\Controller.MarketsController.Index()中的ABC.StaticData.Editor.Controllers.MarketsController.Index()处:第306行
有没有人知道是什么导致了问题,或者从哪里开始寻找

更新:我忘了提到第一点,如果我们在一段时间内不访问该网站,然后返回,它会给出相同的错误-然后再次工作

UPDATE2:这是事件日志条目文本:

WebHost failed to process a request.
 Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/3043589
 Exception: System.ServiceModel.ServiceActivationException: The service '/ABCStaticData/StaticDataService.svc' cannot be activated due to an exception during compilation.  The exception message is: Could not load type 'System.Runtime.CompilerServices.AsyncStateMachineAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.. ---> System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.AsyncStateMachineAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable)
   at System.Reflection.CustomAttribute.IsDefined(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit)
   at System.Reflection.RuntimeMethodInfo.IsDefined(Type attributeType, Boolean inherit)
   at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.HasAttribute(MemberInfo member, Type type)
   at Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject(MemberInfo member)
   at Ninject.Selection.Selector.<>c__DisplayClassa.<SelectMethodsForInjection>b__9(IInjectionHeuristic h)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Ninject.Selection.Selector.<SelectMethodsForInjection>b__8(MethodInfo m)
   at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
   at Ninject.Planning.Strategies.MethodReflectionStrategy.Execute(IPlan plan)
   at Ninject.Planning.Planner.<>c__DisplayClass1.<CreateNewPlan>b__0(IPlanningStrategy s)
   at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[T](IEnumerable`1 series, Action`1 action)
   at Ninject.Planning.Planner.CreateNewPlan(Type type)
   at Ninject.Planning.Planner.GetPlan(Type type)
   at Ninject.Activation.Providers.StandardProvider.Create(IContext context)
   at Ninject.Activation.Context.Resolve()
   at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent)
   at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent)
   at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target)
   at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Ninject.Activation.Providers.StandardProvider.Create(IContext context)
   at Ninject.Activation.Context.Resolve()
   at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent)
   at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent)
   at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target)
   at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Ninject.Activation.Providers.StandardProvider.Create(IContext context)
   at Ninject.Activation.Context.Resolve()
   at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at Ninject.Extensions.Wcf.BaseNinjectServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses)
   at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity)
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
   --- End of inner exception stack trace ---
   at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
   at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath, EventTraceActivity eventTraceActivity)
 Process Name: w3wp
 Process ID: 3248
WebHost无法处理请求。
发件人信息:System.ServiceModel.ServiceHostingEnvironment+HostingManager/3043589
异常:System.ServiceModel.ServiceActivationException:由于编译期间出现异常,无法激活服务“/ABCStaticData/StaticDataService.svc”。异常消息为:无法从程序集“mscorlib,版本=4.0.0,区域性=中立,PublicKeyTok”加载类型“System.Runtime.CompilerServices.AsyncStateMachineAttribute”en=b77a5c561934e089'..->System.TypeLoadException:无法从程序集“mscorlib,版本=4.0.0.0,区域性=中性,PublicKeyToken=b77a5c561934e089”加载类型“System.Runtime.CompilerServices.AsyncStateMachineAttribute”。
在System.ModuleHandle.ResolveType(运行时模块模块、Int32 typeToken、IntPtr*typeInstArgs、Int32 typeInstCount、IntPtr*methodInstArgs、Int32 methodInstCount、ObjectHandleOnStack类型)
位于System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule模块、Int32 typeToken、RuntimeTypeHandle[]TypeInstanceContext、RuntimeTypeHandle[]MethodInstanceContext)
位于System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken,类型[]genericTypeArguments,类型[]genericMethodArguments)
在System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord,MetadataImport作用域,Assembly&LastAptCookAssembly,RuntimeModule decoratedModule,MetadataToken decoratedToken,RuntimeType attributeFilterType,Boolean必须不可编辑,Object[]属性、IList-derivedAttributes、RuntimeType和attributeType、IRontimeMethodInfo和ctor、Boolean和ctorHasParameters、Boolean和isVarArg)
在System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule,Int32 decoratedMetadataToken,RuntimeType attributeFilterType,Boolean必须不可编辑)
在System.Reflection.CustomAttribute.IsDefined(RuntimeMethodInfo方法、RuntimeType caType、布尔继承)
在System.Reflection.RuntimeMethodInfo.IsDefined(类型attributeType,布尔继承)
位于Ninject.Infrastructure.Language.ExtensionsFormMemberInfo.HasAttribute(MemberInfo成员,类型)
在Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject(MemberInfo成员)
在Ninject.Selection.Selector.c_uuu显示ClassA.b_uuu9(iInjecth)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source,Func`2谓词)
在Ninject.Selection.Selector.b____8(MethodInfo m)
在System.Linq.Enumerable.WhererrayInterator`1.MoveNext()中
在Ninject.Planning.Strategies.MethodReflectionStrategy.Execute(IPlan计划)
在Ninject.Planning.Planner.c__显示类1.b___0(iPlanningStrategys)
位于Ninject.Infrastructure.Language.extensionsforIEnumerableSoft.Map[T](IEnumerable`1系列,Action`1 Action)
在Ninject.Planning.Planner.CreateNewPlan(类型)
在Ninject.Planning.Planner.GetPlan(类型)
位于Ninject.Activation.Providers.StandardProvider.Create(IContext上下文)
在Ninject.Activation.Context.Resolve()处
System.ServiceModel.ServiceActivationException: The requested service, 'XXX' could not be activated. See the server's diagnostic trace logs for more information.

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(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)
WebHost failed to process a request.
 Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/58366981
 Exception: System.ServiceModel.ServiceActivationException: The service 'xxx' cannot be activated due to an exception during compilation.  The exception message is: Memory gates checking failed because the free memory (xxx bytes) is less than 5% of total memory.  As a result, the service will not be available for incoming requests.  To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.. ---> System.InsufficientMemoryException: Memory gates checking failed because the free memory (xxx bytes) is less than 5% of total memory.  As a result, the service will not be available for incoming requests.  To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.
<configuration>
  <system.serviceModel>
    <serviceHostingEnvironment ... minFreeMemoryPercentageToActivateService="0" />
  </system.serviceModel>
</configuration>
<%@ ServiceHost Language="C#" Debug="true" Service="YourNamespace.yourService.svc" CodeBehind="yourService.svc.cs" %>
<serviceHostingEnvironment  minFreeMemoryPercentageToActivateService="1">
"%WINDIR%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -r