2012-08-28 2 views
0

우리는 WCF 클라이언트 메시지 검사기를 사용하여 http 헤더에서 상관 ID (및 기타 값)를 읽는 솔루션을 제공합니다.웹 서비스 요청 내에서 정보 공유

이 값을 System.ServiceModel.OperationContext.Current.IncomingMessageProperties에 저장합니다.

OperationContext.Current는 현재 스레드의 실행 컨텍스트입니다.

그러나 Jon Skeet의 답변에 따르면이 질문은 Will a request in IIS run on a single thread? 입니다. asp.net 요청은 스레드간에 점프됩니다.

이것은 정확히 우리가 경험하고있는 것입니다. 요청 실행 중에 상관 ID가 변경됩니다.

http 요청의 값을 저장할 수있는 곳이 스택에 더 낮게 액세스 할 수 있습니까? 나는 우리가 MessageInspector에서 주운 값을 저장하기 위해 System.Web.HttpContext.Current.Items 모음을 사용했습니다

+0

은 아마 메시지 관리자가 다른 스레드에서 실행되어 작동합니다. –

답변

2

, 예를 들어 동일한 키를 사용하여 다른 곳에서 값이 Items 컬렉션에서 포착 할 수있는 스택

public void AfterReceiveReply(ref Message reply, object correlationState) 
    { 
     var httpResponse = 
      reply.Properties[HttpResponseMessageProperty.Name] 
        as HttpResponseMessageProperty; 

     if (httpResponse != null) 
     { 
      string cookie = httpResponse.Headers[HttpResponseHeader.SetCookie]; 

      if (!string.IsNullOrEmpty(cookie)) 
      { 
       System.Web.HttpContext.Current.Items.Add("MyCookies", cookie); 
      } 
     } 
    } 

.

자세한 내용은 Scott Hanselman이 article을 확인하십시오.

+0

감사합니다. –

1

이 날

var headers =OperationContext.Current.IncomingMessageProperties["httpRequest"]; 
     var apiToken = ((HttpRequestMessageProperty)headers).Headers["apiKey"];