using System; using System.Collections.Generic; using System.Text; using System.Security.Cryptography.X509Certificates; using System.Net; using System.Net.Security; using RemoteSearchClient.RemoteSearchService; using System.Reflection; using System.Web.Services.Protocols; namespace RemoteSearchClient { class Program { /* * The method does the RemoteCertificateValidation. * We are concerned about following types of cert errors * 1. Untrusted root * 2. Common name not match * 3. Expired or not yet effective * 4. Revoked * * However this method will return true only if there is no * sslPolicyErrors other than RevocationStatusUnknown. */ public static bool myCertificateValidation(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { Console.WriteLine("Subject: {0}", certificate.Subject); Console.WriteLine("Issuer : {0}", certificate.Issuer); Console.WriteLine("Serial : {0}", certificate.GetSerialNumberString()); Console.WriteLine("Expires: {0}", certificate.GetExpirationDateString()); Console.WriteLine("Effective Date: {0}", certificate.GetEffectiveDateString()); X509Certificate2 cert2 = new X509Certificate2(certificate); Console.WriteLine("Now: {0}", DateTime.Now); Console.WriteLine("Not after: {0}", cert2.NotAfter); if (cert2.NotAfter < DateTime.Now) Console.WriteLine("*** Certificate has expired!!!"); else if (cert2.NotBefore > DateTime.Now) Console.WriteLine("*** Certificate is not effective yet!!"); else if (cert2.NotAfter.AddDays(-30.0) < DateTime.Now) Console.WriteLine("*** Certificate expires in thirty days or less!!!"); if (sslPolicyErrors.Equals(SslPolicyErrors.None)) return true; if (sslPolicyErrors.Equals(SslPolicyErrors.RemoteCertificateChainErrors)) { if (chain.ChainStatus[0].Status.Equals(X509ChainStatusFlags.RevocationStatusUnknown)) return true; Console.WriteLine("Chain Status: {0}", chain.ChainStatus[0].Status); Console.WriteLine("Chain Status Information: {0}", chain.ChainStatus[0].StatusInformation); return false; } if (sslPolicyErrors.Equals(SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateChainErrors)) { Console.WriteLine("CertificateErrors: {0}", SslPolicyErrors.RemoteCertificateNameMismatch); if (!chain.ChainStatus[0].Status.Equals(X509ChainStatusFlags.RevocationStatusUnknown)) Console.WriteLine("Chain Status Information: {0}", chain.ChainStatus[0].StatusInformation); return false; } Console.WriteLine("Certificate error: {0}", sslPolicyErrors); Console.WriteLine("Request URL: {0}", ((WebRequest)sender).RequestUri); return false; } /* * Call back method to handle the RemoteSearchCompleted event. * Currently only check the "Result" field. * It is also possible to check "Canceled", "error" and "UserState" * Fields of the param "RemoteSearchCompletedEventArgs" */ public static void myRemoteSearchCompletedEventHandler(object sender, RemoteSearchCompletedEventArgs e) { /* * If the response is not null, output the recordCount and search result details. */ try { if (e.Result != null) { if (e.Result.Item is WijisSearchResultType) { WijisSearchResultType response = e.Result.Item as WijisSearchResultType; Console.WriteLine("*******************Confirmation Response!!**********************"); Console.WriteLine("recordCount:" + response.recordCount); WijisSubmitterAwarePointerType[] pointerSAArray = response.pointersFound.pointerSA; if (pointerSAArray != null) { foreach (WijisSubmitterAwarePointerType pointer in pointerSAArray) { Console.WriteLine("Record Designator: " + pointer.recordDesignator); if (pointer.sensitivityFlags.juvenileSpecified) { Console.WriteLine("Juvenile Flag: " + pointer.sensitivityFlags.juvenile); } if (pointer.sensitivityFlags.openInvestigationSpecified) { Console.WriteLine("Open Investigation Flag: " + pointer.sensitivityFlags.openInvestigation); } if (pointer.sensitivityFlags.sexualAssaultSpecified) { Console.WriteLine("Sexual Assault Flag: " + pointer.sensitivityFlags.sexualAssault); } if (pointer.Item is PointerContentType) { PointerContentType pointerContent = (PointerContentType)pointer.Item; Object[] itemsArray = pointerContent.Items; foreach (Object item in itemsArray) { if (item is PersonActivityHeaderType) { PersonActivityHeaderType pah = (PersonActivityHeaderType)item; Console.WriteLine("Name Prefix: " + pah.personNamePrefix); Console.WriteLine("First Name: " + pah.personFirstName); Console.WriteLine("Middle Name: " + pah.personMiddleName); Console.WriteLine("Last Name: " + pah.personLastName); Console.WriteLine("Name Suffix: " + pah.personNameSuffix); Console.WriteLine("Person Role: " + pah.personRole); Console.WriteLine("Record Caption: " + pah.recordCaption); Console.WriteLine("Record Holder Caption: " + pah.recordholderCaption); } if (item is PersonActivitySupplementalType) { PersonActivitySupplementalType personSupplemental = (PersonActivitySupplementalType)item; Console.WriteLine("Eye Color: " + personSupplemental.personEyeColor); Console.WriteLine("Hair Color: " + personSupplemental.personHairColor); Console.WriteLine("Height: " + personSupplemental.personHeight); Console.WriteLine("Sex: " + personSupplemental.personSex); Console.WriteLine("Weight: " + personSupplemental.personWeight); } } } } } } } } catch (TargetInvocationException tie) { Console.WriteLine("*******************TargetInvocationException**********************"); Console.WriteLine(tie.InnerException.Message); if (tie.InnerException is SoapException) { SoapException soapException = tie.InnerException as SoapException; Console.WriteLine(soapException.Detail.InnerText); } } Console.Read(); } static void Main(string[] args) { RemoteGatewaySearch server = new RemoteGatewaySearch(); //Uncomment one of following statements to change the url of the service. server.Url = "https://wijisgwtest.wisconsin.gov:17444/WijisGatewayRemoteSearch/RemoteGatewaySearchService/RemoteSearch"; //server.Url = "https://wijis.wisconsin.gov:17444/WijisGatewayRemoteSearch/RemoteGatewaySearchService/RemoteSearch"; /* * Check the Server certificate. The connection will fail if the server is * holding an invalid key. */ ServicePointManager.CheckCertificateRevocationList = true; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(myCertificateValidation); /* * Set the Client certificate to server. */ string certFile = "MyCertificate.cer"; X509Certificate cert = new X509Certificate(certFile, "password"); Console.WriteLine(server.Url.ToString()); Console.WriteLine(cert.Subject); server.ClientCertificates.Add(cert); /* * Create a PersonSearchInstruction type and set it to server. * Replace the opratorURIs with your operatorURI. The operatorURI can * be found on http://www.wijiscommons.org/uri */ PersonSearchInstructionsType psit = RemoteSearchHelper.createRemoteSearchRequest(); ResponseType samlAssertion = RemoteSearchHelper.createSamlAssertion(); server.Response = samlAssertion; /* * Call the service and get the response. */ try { /* * Call the service and the results will be handled by the callback method myRemoteSearchCompletedEventHandler */ server.RemoteSearchCompleted += new RemoteSearchCompletedEventHandler(myRemoteSearchCompletedEventHandler); server.RemoteSearchAsync(psit); } catch (Exception e) { Console.WriteLine(e.Message); } Console.Read(); } } }