2012-04-23 16 views
1

私はAzureでWCFの自己ホストサービスを利用しています。私はデスクトップクライアントとMetroスタイルのApp Clientを作ろうとしています。私は、輸送のセキュリティと自己署名入りの証明書を使ってnettcpbindingを使用しています。 Windows 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つの選択肢は、1〜2週間待って、リリースプレビューがもたらすものを確認することです。 –

関連する問題