/// <summary>
        /// Create a Verified IHI service call.
        /// </summary>
        /// <param name="request">
        /// The create criteria. The following fields are expected:
        /// <list type="bullet">
        /// <item><description>familyName (Mandatory)</description></item>
        /// <item><description>givenName (Optional)</description></item>
        /// <item><description>dateOfBirth (Mandatory)</description></item>
        /// <item><description>sex (Mandatory)</description></item>
        /// <returns>
        /// A createVerifiedIHIResponse instance containing:
        /// <list type="bullet">
        /// <item><description>IHI number</description></item>
        /// <item><description>IHI record status</description></item>
        /// <item><description>IHI status</description></item>
        /// <item><description>serviceMessage (optional)</description></item>
        /// </list>
        /// </returns>
        public createVerifiedIHIResponse CreateVerifiedIhi(createVerifiedIHI request)
        {
            Validation.ValidateArgumentRequired("request", request);
            Validation.ValidateDateTime("request.dateOfBirth", request.dateOfBirth);
            Validation.ValidateArgumentRequired("request.dateOfBirthAccuracyIndicator", request.dateOfBirthAccuracyIndicator);
            Validation.ValidateArgumentRequired("request.sex", request.sex);
            Validation.ValidateArgumentRequired("request.familyName", request.familyName);
            Validation.ValidateArgumentRequired("request.usage", request.usage);
            Validation.ValidateArgumentRequired("request.address", request.address);
            Validation.ValidateArgumentRequired("request.privacyNotification", request.privacyNotification);

            return(IHICreateVerified(request));
        }
        /// <summary>
        /// Perform the IHI service call.
        /// </summary>
        /// <param name="request">The criteria in a createVerifiedIHI object.</param>
        /// <returns>The IHI create results.</returns>
        private createVerifiedIHIResponse IHICreateVerified(createVerifiedIHI request)
        {
            createVerifiedIHIRequest envelope = new createVerifiedIHIRequest();

            envelope.createVerifiedIHI = request;
            envelope.product           = product;
            envelope.user      = user;
            envelope.hpio      = hpio;
            envelope.signature = new SignatureContainerType();

            envelope.timestamp = new TimestampType()
            {
                created          = DateTime.Now.ToUniversalTime(),
                expires          = DateTime.Now.AddDays(30).ToUniversalTime(),
                expiresSpecified = true
            };

            // Set LastSoapRequestTimestamp
            LastSoapRequestTimestamp = envelope.timestamp;

            createVerifiedIHIResponse1 response1 = null;

            try
            {
                response1 = createVerifiedIhiClient.createVerifiedIHI(envelope);
            }
            catch (Exception ex)
            {
                // Catch generic FaultException and call helper to throw a more specific fault
                // (FaultException<ServiceMessagesType>
                FaultHelper.ProcessAndThrowFault <ServiceMessagesType>(ex);
            }

            if (response1 != null && response1.createVerifiedIHIResponse != null)
            {
                return(response1.createVerifiedIHIResponse);
            }
            else
            {
                throw new ApplicationException(Properties.Resources.UnexpectedServiceResponse);
            }
        }
        public void Sample()
        {
            // ------------------------------------------------------------------------------
            // Set up
            // ------------------------------------------------------------------------------

            // Obtain the certificate by serial number
            X509Certificate2 tlsCert = X509CertificateUtil.GetCertificate(
                "Serial Number",
                X509FindType.FindBySerialNumber,
                StoreName.My,
                StoreLocation.CurrentUser,
                true
                );

            // The same certificate is used for signing the request.
            // This certificate will be different to TLS cert for some operations.
            X509Certificate2 signingCert = tlsCert;

            // Set up client product information (PCIN)
            // Values below should be provided by Medicare
            ProductType product = new ProductType()
            {
                platform       = "Your system platform (Eg. Windows XP SP3)", // Can be any value
                productName    = "Product Name",                              // Provided by Medicare
                productVersion = "Product Version",                           // Provided by Medicare
                vendor         = new QualifiedId()
                {
                    id        = "Vendor Id",                                // Provided by Medicare
                    qualifier = "Vendor Qualifier"                          // Provided by Medicare
                }
            };

            // Set up user identifier details
            QualifiedId user = new QualifiedId()
            {
                id        = "User Id",                                      // User ID internal to your system
                qualifier = "http://<anything>/id/<anything>/userid/1.0"    // Eg: http://ns.yourcompany.com.au/id/yoursoftware/userid/1.0
            };

            // Set up user identifier details
            QualifiedId hpio = new QualifiedId()
            {
                id        = "HPIO",                                       // HPIO internal to your system
                qualifier = "http://<anything>/id/<anything>/hpio/1.0"    // Eg: http://ns.yourcompany.com.au/id/yoursoftware/userid/1.0
            };

            // ------------------------------------------------------------------------------
            // Client instantiation and invocation
            // ------------------------------------------------------------------------------

            // Instantiate the client
            ConsumerCreateVerifiedIHIClient client = new ConsumerCreateVerifiedIHIClient(
                new Uri("https://HIServiceEndpoint"),
                product,
                user,
                hpio,
                signingCert,
                tlsCert);

            // Set up the request
            createVerifiedIHI request = new createVerifiedIHI();

            request.dateOfBirth = DateTime.Parse("01 Dec 2014");
            request.dateOfBirthAccuracyIndicator = DateAccuracyIndicatorType.AAA;
            request.familyName = "Wood";
            request.givenName  = new [] { "Jessica" };
            request.sex        = SexType.F;
            request.usage      = IndividualNameUsageType.L;
            request.address    = new AddressType();
            request.address.australianStreetAddress = new AustralianStreetAddressType();
            request.address.australianStreetAddress.streetNumber        = "10";
            request.address.australianStreetAddress.streetName          = "Browning Street";
            request.address.australianStreetAddress.streetType          = StreetType.ST;
            request.address.australianStreetAddress.streetTypeSpecified = true;
            request.address.australianStreetAddress.suburb   = "West End";
            request.address.australianStreetAddress.postcode = "4101";
            request.address.australianStreetAddress.state    = StateType.QLD;
            request.address.purpose     = AddressPurposeType.R;
            request.address.preferred   = TrueFalseType.T;
            request.privacyNotification = true;

            try
            {
                // Invokes a basic search
                createVerifiedIHIResponse ihiResponse = client.CreateVerifiedIhi(request);
            }
            catch (FaultException fex)
            {
                string       returnError = "";
                MessageFault fault       = fex.CreateMessageFault();
                if (fault.HasDetail)
                {
                    ServiceMessagesType error = fault.GetDetail <ServiceMessagesType>();
                    // Look at error details in here
                    if (error.serviceMessage.Length > 0)
                    {
                        returnError = error.serviceMessage[0].code + ": " + error.serviceMessage[0].reason;
                    }
                }

                // If an error is encountered, client.LastSoapResponse often provides a more
                // detailed description of the error.
                string soapResponse = client.SoapMessages.SoapResponse;
            }
            catch (Exception ex)
            {
                // If an error is encountered, client.LastSoapResponse often provides a more
                // detailed description of the error.
                string soapResponse = client.SoapMessages.SoapResponse;
            }
        }