複数のWCFサービスがすべてInstanceContextMode=PerCallで動作し、すべてのWCFサービスインスタンスはUnity(IOC)を使用してIInstanceProviderを実装することで生成されます。
相関識別子は、同じ識別子を持つすべてのメソッド呼び出しとデータベースプロセスを監査するために使用されます。
これを実現するために、IDispatchBehaviorを実装することでエンドポイントの動作が作成され、AfterReceiveRequestメソッドでGUIDが生成され、ThreadStatic(CommonData
)プロパティに割り当てられます。このプロパティは、アプリケーションのすべてのレイヤーでアクセスできます。次のコードブロックは、CommonDataの母集団とCommonDataクラスを示しています。
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
CommonData.ClearDictionary();
//the lines between are deleted as they are not relevant to the question
CommonData.Current.Add(MessageHeaderCodes.CorrelationId, Guid.NewGuid().ToString());
return null;
}
およびcommondataクラス:
public class CommonData
{
[ThreadStatic]
private static Dictionary<string, string> headerData;
public static Dictionary<string, string> Current
{
get
{
if (headerData == null)
{
headerData = new Dictionary<string, string>();
}
return headerData;
}
}
private CommonData()
{
}
public static string GetHeader(string header)
{
string headerValue = string.Empty;
KeyValuePair<string, string> headerKeyValuePair = CommonData.Current.SingleOrDefault(p => p.Key == header);
headerValue = headerKeyValuePair.Value;
return headerValue;
}
public static void ClearDictionary()
{
Current.Clear();
}
}
The problem here is the following; In some of the services, developers reported that the correlation identifier returns null. Since the problem is intermittant it is not possible to have a full stack trace at the moment. Also, they stated that reseting IIS resolves this problem temporarily.
Any help is appreciated...