2012-04-23 3 views
1

나는 Azure에 WCF 자체 호스팅 서비스를 가지고있다. 데스크톱 클라이언트와 Metro 스타일 앱 클라이언트를 만들려고합니다. nettcpbinding 전송 보안 및 자체 서명 된 인증서를 사용하고 있습니다. 윈도우 7에메트로 스타일 앱에서 CertificateValidationMode를 설정하는 방법은 무엇입니까?

이 코드는 작동합니다

client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 
client.GetUpdate(...); 

하지만 필드 ServiceCertificate이 존재하지 않는 지하철 응용 프로그램에, 그래서

The X.509 certificate CN=SPDEV-1-PC chain building failed. 
The certificate that was used has a trust chain that cannot be verified. 
Replace the certificate or change the certificateValidationMode. 
A certificate chain processed, but terminated in a root certificate 
which is not trusted by the trust provider. 

어떻게 수행 (예정) 예외를 받고 있어요

certificateValidationMode를 변경합니까?

답변

0

나는 비슷한 문제에 직면했다. 나는 이것을 반영하여 해결했다. 시도해보십시오. 이 같은 :

Type credType = typeof (ClientCredential); //enter here type of your credentials 
PropertyInfo credPropInfo1 = credType.GetTypeInfo().GetDeclaredProperty("ServiceCertificate"); 
PropertyInfo credPropInfo2 = credPropInfo1.GetType().GetTypeInfo().GetDeclaredProperty("Authentication"); 
PropertyInfo credPropInfo3 = credPropInfo2.GetType().GetTypeInfo().GetDeclaredProperty("CertificateValidationMode"); 
credPropInfo3.SetValue(yourObject, 0); // use the int value of the enum, suggested 0 for None 

업데이트 : 여기에 나를 위해 잘 실행 바보 코드) 나는 그것을 재현 할 수 없기 때문에

var test6 = client.ClientCredentials.GetType().GetTypeInfo().GetDeclaredProperty("ServiceCertificate").GetValue(client.ClientCredentials); 
var test7 = test6.GetType().GetTypeInfo().GetDeclaredProperty("Authentication").GetValue(test6); 
test7.GetType().GetTypeInfo().GetDeclaredField("certificateValidationMode").SetValue(test7, 0); 
test6.GetType().GetTypeInfo().GetDeclaredField("authentication").SetValue(test6, test7); 
client.ClientCredentials.GetType().GetTypeInfo().GetDeclaredField("serviceCertificate").SetValue(client, test6); 
+0

credPopInfo2, 나는 당신에게 올바른 코드를 제공 할 수없는 널 –

+0

입니다. 직접 실행 창에서 프로그램을 실행하는 동안 속성에 액세스하십시오. 더 많은 네임 스페이스를 사용할 수 있습니다. 런타임 중에 즉시 창을 통해 액세스 할 수 있으면 리플렉션을 사용하여 속성을 수정할 수도 있습니다. –

+0

위 코드를 업데이트했습니다. 이것은 나를 위해 작동합니다. 또 다른 옵션은 1-2 주를 기다린 후 출시 일정 미리보기를 보는 것입니다. –

관련 문제