.svc ファイルに次のコードを含む非常に基本的な WCF サービス アプリケーションを作成しました。
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
namespace NamesService
{
[ServiceContract]
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class NamesService
{
List<string> Names = new List<string>();
[OperationContract]
[AspNetCacheProfile("CacheFor60Seconds")]
[WebGet(UriTemplate="")]
public List<string> GetAll()
{
return Names;
}
[OperationContract]
public void Save(string name)
{
Names.Add(name);
}
}
}
そして、web.config は次のようになります。
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.web>
<caching>
<outputCache enableOutputCache="true"/>
<outputCacheSettings>
<outputCacheProfiles>
<add name="CacheFor60Seconds" location="Server" duration="60" varyByParam="" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
</system.web>
ご覧のとおり、GetAll メソッドは AspNetCacheProfile で修飾されており、cacheProfileName は web.config の「ChacheFor60Seconds」セクションを参照しています。
WCF テスト クライアントで次のシーケンスを実行します。
1) パラメータ "Fred" を指定して Save を呼び出します
2) GetAll を呼び出します -> 予想どおり、"Fred" が返されます。
3) パラメータ "Bob" を指定して Save を呼び出す
4) GetAll を呼び出す -> 今度は "Fred" と "Bob" が返されます。
手順 (2) からキャッシュされた結果を返す必要があるため、GetAll の 2 回目の呼び出しで "Fred" のみが返されることを期待していました。
何が問題なのかわからないので、助けていただければ幸いです。