// Acquires a root certificate from the service utility endpoint and // attempts to install it into the root store. It returns the // certificate in the store, which may include one that was already // installed. Exceptions are propagated to the caller. private static X509Certificate2 InstallRootCertificateFromServer() { X509Certificate2 rootCertificate = null; BasicHttpBinding basicHttpBinding = new BasicHttpBinding(); ChannelFactory <IUtil> factory = null; IUtil serviceProxy = null; try { factory = new ChannelFactory <IUtil>(basicHttpBinding, new EndpointAddress(ServiceUtil_Address)); serviceProxy = factory.CreateChannel(); rootCertificate = new X509Certificate2(serviceProxy.GetRootCert(false)); rootCertificate = CertificateManager.InstallCertificateToRootStore(rootCertificate); } finally { CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } return(rootCertificate); }
public static bool GetCertificate(out byte[] certificateBytes) { certificateBytes = default(byte[]); string address = ServiceUtilHelper.ServiceUtil_Address; Console.WriteLine(" Retrieving certificate from:" + address); ChannelFactory <IUtil> factory = null; IUtil serviceProxy = null; BasicHttpBinding basicHttpBinding = new BasicHttpBinding(); try { factory = new ChannelFactory <IUtil>(basicHttpBinding, new EndpointAddress(address)); serviceProxy = factory.CreateChannel(); certificateBytes = serviceProxy.GetRootCert(true); Console.WriteLine(" ... read {0} bytes from Bridge", certificateBytes.Length); return(true); } finally { CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory); } }