2013-05-08 5 views
0

즉석에서 wcf 요청에 헤더 정보 (또는 쿼리 문자열)를 추가 할 수 있습니까? 나는이 같은 IWcfPolicy와 약간 장난 봤는데 :IWcfPolicy - 즉석에서 메시지 헤더 추가

var xmlObjectSerializer = new DataContractSerializer(typeof(string)); 

    var addressHeader = AddressHeader.CreateAddressHeader("client", "http://tempuri.org/", "someValue", xmlObjectSerializer); 

    var endpointAddress = new EndpointAddress(new Uri(url), new AddressHeader[] { addressHeader }); 

    invocation.ChannelHolder.ChannelFactory.Endpoint.Address = endpointAddress; 

    invocation.Proceed(); 

이 있지만 작동하지 않습니다. 어떤 도움이라도 대처할 것입니다. 그래서 여기에 확인

답변

1

그것을 할 방법은 다음과 같습니다

using (var scope = new OperationContextScope((IContextChannel) (invocation.ChannelHolder.Channel))) 
       { 
        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = new HttpRequestMessageProperty 
         () 
         { 
          Headers = 
           { 
            {"client", LicenseManager.Instance.GetCurrentLicense().LicenseKey} 
           } 
         }; 

        invocation.Proceed(); 
       } 

이 코드는 IWcfPolicy 구현의 방법을 적용로 들어갑니다. 이 게시물로 인해 발견 된 솔루션 : how to add a custom header to every wcf call