Exemple #1
0
 public ProvisioningDeviceClient(Microsoft.Azure.Devices.Provisioning.Client.ProvisioningDeviceClient provisioningDeviceClient, SecurityProvider security)
 {
     _provClient = provisioningDeviceClient;
     _security   = security;
 }
        public async Task <DeviceClient> StartProvisioningAsync()
        {
            ServicePointManager
            .ServerCertificateValidationCallback +=
                (sender, cert, chain, sslPolicyErrors) => true;

            X509Certificate2 rootCA      = LoadCertificate("574D9333C86537BC99070353EF1A8C8C50B0B5AE");
            X509Certificate2 certificate = LoadCertificate(_provThumbprint);


            var myChain = new X509Certificate2Collection();

            myChain.Add(rootCA);
            myChain.Add(certificate);

            using (var security = new SecurityProviderX509Certificate(certificate, myChain))

                using (var transport = new ProvisioningTransportHandlerHttp())
                {
                    Microsoft.Azure.Devices.Provisioning.Client.ProvisioningDeviceClient provClient =
                        Microsoft.Azure.Devices.Provisioning.Client.ProvisioningDeviceClient.Create(GlobalDeviceEndpoint, s_idScope, security, transport);

                    var sample = new ProvisioningDeviceClient(provClient, security);
                    return(sample.ProvisionDeviceAndGetClientAsync().GetAwaiter().GetResult());
                }
        }