2013-04-21 6 views
1

ServiceDescriptionImporter를 사용하여 wsdl에서 동적으로 웹 서비스 클라이언트를 생성하고 있습니다.HttpSoapClientProtocol에 HTTP 헤더 추가하기

인증 (기본)이 필요한 서비스를 호출 할 때까지 모든 것이 잘 작동합니다. 내가 생성 한 클라이언트가 보낸 요청에 기본 인증 헤더를 추가 할 수있는 방법을 찾지 못했습니다.

다음을 시도했지만 작동하지 않습니다. 나는 아직도 얻을 401 :

var webClient = obj as HttpSoapClientProtocol; 
CredentialCache mycache = new CredentialCache(); 
// Credentials are specified here 
mycache.Add(new Uri("http://localhost:9999/MyService"), "Basic", new NetworkCredential("username", "password")); 
webClient.Credentials = mycache; 

가 어떻게이 웹 클라이언트 (HttpWebClientProtocol)에 HTTP 헤더를 추가 할 수 있습니까?

/Andreas

답변

0

문제가 해결되었습니다. 나는 거의 옳았다. PreAuthenticate을 true로 설정해야했습니다.

var webClient = obj as HttpWebClientProtocol; 
NetworkCredential netCredential = new NetworkCredential("username", "password"); 
Uri uri = new Uri("http://localhost:9999/MyService"); 
ICredentials credentials = netCredential.GetCredential(uri, "Basic"); 
webClient.Credentials = credentials; 
webClient.PreAuthenticate = true; 
: 여기

올바른 코드