web-dev-qa-db-ja.com

MVCサイトから最初にアクセスしたときに「要求されたサービス '...'をアクティブ化できませんでした」を返すWCFサービス

MVC3 Webサイトからアクセスされている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

誰が問題を引き起こしているのか、どこから探し始めるのかについてのアイデアを持っていますか?

更新:最初に言及するのを忘れていましたが、しばらくサイトにアクセスせずに戻った場合、同じエラーが発生し、2度目に再び動作します。

更新2:これはイベントログエントリのテキストです。

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

.NET 4.5とVisual Studio 2012 RCを使用して開発しているもう1つのポイント。

27
trembler2003

ランダムな 'System.ServiceModel.ServiceActivationException'(例外をスローし、2回目のヒットで実行)の同様の問題を解決できました。私の場合の例外の理由は、サーバーのメモリ不足でした。メモリの問題を確認するには、次を実行できます。

Webサービスを呼び出すアプリケーション:

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)

WCFトレースログ:何も記録されません。

私が見つけたがらくたの情報の多くを除いて、イベントログのwcfサービスをホストしているサーバー(呼び出し元のアプリケーションbtwと同じ):

カスタムイベントの詳細:

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.

したがって、私にとっての解決策は次のとおりです。1. RAMを追加します2. RAMの一部をリリースします(一時的なソリューション)3. WebサービスのWeb設定を更新します。

<configuration>
  <system.serviceModel>
    <serviceHostingEnvironment ... minFreeMemoryPercentageToActivateService="0" />
  </system.serviceModel>
</configuration>
27

私もこの問題を抱えていました。

<serviceHostingEnvironment  minFreeMemoryPercentageToActivateService="1">

<system.serviceModel>

そして、すべてが正常に動作します。

12
vsp

私は同じ「タイプ 'System.Runtime.CompilerServices.AsyncStateMachineAttribute'をロードできませんでした」というヒットを見つけました。これは、VS 2012 RTMを使用してアプリケーションを構築したが、 4.5ベータ。 AsyncStateMachineAttributeは、ベータ後に追加された新しいタイプです。

2
Tratcher

IISで.svc拡張子が登録されていますか?

詳細については [〜#〜] msdn [〜#〜] を参照してください。

0
Jocke

サービスをホストしているサーバーのメモリがいっぱいではないことを確認します。

0
Hasan

今日、この同じ問題に遭遇しましたが、代わりにRAMがディスク領域であった問題です。領域を解放した後、アプリケーションプールを再起動する必要があり、問題は解決しました。

0
Kirk

私もその問題を抱えていました、私がしたことは:

  • サービスが存在するファイルシステムのディレクトリに移動します
  • サービス用に2つのファイルがあります。
    • yourService.svc
    • yourService.svc.cs
  • ファイルyourService.svcを開き、サービスが構成されていることを確認します。コードビハインドは次のようになります。

    <%@ ServiceHost Language="C#" Debug="true" Service="YourNamespace.yourService.svc" CodeBehind="yourService.svc.cs" %>
    

そのようにして問題を修正しました。私はそれが役立つことを願っています!

0

このエラーは、Windows Communication Foundation(WCF)のインストール後にIISをインストールした場合に発生します。修正するには、次のコマンドを実行します。

"%WINDIR%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -r

ソース: IIS Hosted Service Fails

0
CSharper