Address Insight C# Code Snippet

public partial class AIN_Form : System.Web.UI.Page
   {
       const string TrialURL = "https://trial.serviceobjects.com/ain/soap.svc/SOAP";
       // A trial license key is not compatible with the backup datacenter.
       // The backup url is provided with a production license key.
       const string BackupURL = "https://trial.serviceobjects.com/ain/soap.svc/SOAP";
       protected void Page_Load(object sender, EventArgs e)
       {
           ErrorLabel.Visible = false;
       }
       protected void btn_Validate_Click(object sender, EventArgs e)
       {
           try
           {
               AIN.ResponseObject response = GetAddressInsight();
               PrintResponse(response);
           }
           catch (Exception ex)
           {
               ErrorLabel.Visible = true;
               ErrorLabel.Text = ex.Message;
           }
       }
       protected AIN.ResponseObject GetAddressInsight()
       {
           AIN.ResponseObject Response = null;
  
           try
           {
               using (AIN.SOAPClient Client = new AIN.SOAPClient())
               {
                   // Implement Failover logic here
                   try
                   {
                       Client.Endpoint.Address = new System.ServiceModel.EndpointAddress(TrialURL);
                       Response = Client.GetAddressInsight(BusinessName.Text,
                                                           Address1.Text,
                                                           Address2.Text,
                                                           City.Text,
                                                           State.Text,
                                                           Zip.Text,
                                                           TestType.Text,
                                                           inputLicenseKey.Text);
                   }
                   catch (WebException)
                   {
                       Client.Endpoint.Address = new System.ServiceModel.EndpointAddress(BackupURL);
                       Response = Client.GetAddressInsight(BusinessName.Text,
                                                           Address1.Text,
                                                           Address2.Text,
                                                           City.Text,
                                                           State.Text,
                                                           Zip.Text,
                                                           TestType.Text,
                                                           inputLicenseKey.Text);
                   }
                   catch (CommunicationException)
                   {
                       Client.Abort();
                   }
                   catch (TimeoutException)
                   {
                       Client.Abort();
                   }
                   catch (Exception Ex)
                   {
                       Client.Abort();
                   }
               }
           }
           catch (Exception)
           {
               // throw;
           }
           return Response;
       }
       protected void PrintResponse(AIN.ResponseObject response)
       {
           DataTable dtProvider = new DataTable();
           //Proccess result
           //We just output it here but this would be a good place to save data
           //to a database or send an email etc.
           dtProvider.Columns.Add(new DataColumn("Output", typeof(string)));
           dtProvider.Columns.Add(new DataColumn("Values", typeof(string)));
           if (response.ContainsKey("AddressInsightResponse"))
           {
               AIN.ResultObject ro = response["AddressInsightResponse"];
               //Loop through the fields
               /*
               foreach (string Key in ro[0].Keys)
               {
                   dtProvider.Rows.Add(Key, ro[0][Key]);
               }
               */
               //Or access the fields directly.
               dtProvider.Rows.Add("Status", ro[0].ContainsKey("Status") ? ro[0]["Status"] : "");
               dtProvider.Rows.Add("StatusScore", ro[0].ContainsKey("StatusScore") ? ro[0]["StatusScore"] : "");
               dtProvider.Rows.Add("AddressStatus", ro[0].ContainsKey("AddressStatus") ? ro[0]["AddressStatus"] : "");
               dtProvider.Rows.Add("DPV", ro[0].ContainsKey("DPV") ? ro[0]["DPV"] : "");
               dtProvider.Rows.Add("DPVDesc", ro[0].ContainsKey("DPVDesc") ? ro[0]["DPVDesc"] : "");
               .
               .
               .
               dtProvider.Rows.Add("ZipHouseholdIncome", ro[0].ContainsKey("ZipHouseholdIncome") ? ro[0]["ZipHouseholdIncome"] : "");
               dtProvider.Rows.Add("CountyHouseholdIncome", ro[0].ContainsKey("CountyHouseholdIncome") ? ro[0]["CountyHouseholdIncome"] : "");
               dtProvider.Rows.Add("StateHouseholdIncome", ro[0].ContainsKey("StateHouseholdIncome") ? ro[0]["StateHouseholdIncome"] : "");
               dtProvider.Rows.Add("ZipNotes", ro[0].ContainsKey("ZipNotes") ? ro[0]["ZipNotes"] : "");
               dtProvider.Rows.Add("ZipNotesCodes", ro[0].ContainsKey("ZipNotesCodes") ? ro[0]["ZipNotesCodes"] : "");
           }
           else
           {
               if (response.ContainsKey("Error"))
               {
                   AIN.ResultObject roError = response["Error"];
                   //Loop throught he fields
                   /*
                   foreach (string Key in roError[0].Keys)
                   {
                       dtProvider.Rows.Add(Key, roError[0][Key]);
                   }
                   */
                   //Or access the fields directly.
                   dtProvider.Rows.Add("Type", roError[0].ContainsKey("Type") ? roError[0]["Type"] : "");
                   dtProvider.Rows.Add("TypeCode", roError[0].ContainsKey("TypeCode") ? roError[0]["TypeCode"] : "");
                   dtProvider.Rows.Add("Desc   ", roError[0].ContainsKey("Desc ") ? roError[0]["Desc   "] : "");
                   dtProvider.Rows.Add("DescCode", roError[0].ContainsKey("DescCode") ? roError[0]["DescCode"] : "");
               }
           }
           ResultGrid.DataSource = new DataView(dtProvider);
           ResultGrid.DataBind();
       }
   }

Address Insight Java Code Snippet

String businessName = request.getParameter("businessName");
String address1 = request.getParameter("address1");
String address2 = request.getParameter("address2");
String city = request.getParameter("city");
String state = request.getParameter("state");
String zip = request.getParameter("zip");
String testType = request.getParameter("testType");
String licenseKey = request.getParameter("licensekey");
  
//Creating the soap client
SOAP soap = new SOAP();
  
ISOAP client = soap.getAddressInsightSOAP();
  
ResponseObject addressPlus;
  
//Call the web service
try{
    addressPlus = client.getAddressInsight(businessName, address1, address2, city, state, zip, testType, licenseKey);
}catch(Exception ex){
    //Create a backup client if an exception is thrown
    ISOAP backupClient = soap.getAddressInsightSOAP();
    addressPlus = backupClient.getAddressInsight(businessName, address1, address2, city, state, zip, testType, licenseKey);
}
  
List<ResponseObject.Response> responses = addressPlus.getResponse();
    %>
    <H2>Service Response</H2>
    <table>
    <%
    for(ResponseObject.Response res : responses){
        ResultObject resList = res.getValue();
        String resultKey = res.getKey();
        %>
            <tr>
                <td><b><%=resultKey%></b></td>
            </tr>
        <%
        List<FieldObject> results = resList.getResult();
        for(FieldObject result : results){
            List<FieldObject.Field> fields = result.getField();
            for(FieldObject.Field kvp : fields){
                String key = kvp.getKey();
                String value = kvp.getValue();
            %>
            <tr>
                <td><%=key%></td>
                <td><%=value%></td>
            </tr>
            <%
                  
            }
        }
    }