Address Validation Canada 2 C# Code Snippet

response = ws.ValidateCanadianAddressV2(Address.Text, Address2.Text, Municipality.Text, Province.Text, PostalCode.Text, Language.Text, LicenseKey.Text);
if ((response == null || (response.Error != null && response.Error.TypeCode == "3")))
{
    throw new Exception();
     
}
else
{
    if (response.Error != null)
        ProcessErrorResponse(response.Error);
    else
        ProcessValidResponse(response.CanadianAddressInfoV2);
}

Address Validation Canada 2 Java Code Snippet

outputs = soap.validateCanadianAddressV2(address, address2, municipality, province, postalcode, language, licenseKey);
avca2error = outputs.getError();
if(avca2error !=null && avca2error.getTypeCode() == "3")
{
    throw new Exception(); 
}
}
catch(Exception e)
{   //FAILOVER- USE BACKUP NOW
    try{
        //CALL SOAP USING BACKUP URL (Change the endpoint)
        outputs = soap.validateCanadianAddressV2(address, address2, municipality, province, postalcode, language, licenseKey);
        avca2error = outputs.getError();
    }
    catch(Exception ex)
    {
     
        throw new Exception("Both Primary and Backup soap calls failed: " + ex.getMessage());
    }
}

Address Validation Canada 2 PHP Code Snippets

$URL = "https://trial.serviceobjects.com/avca2/api.svc?wsdl";
//use backup url once given purchased license key
$backupURL = "https://trial.serviceobjects.com/avca2/api.svc?wsdl";
try{
     
               
                $client = new SoapClient($URL);
    //$soapClient = new SoapClient($URL, array( "trace" => 1 ));
                $outputs = $client->ValidateCanadianAddressV2($params)->ValidateCanadianAddressV2Result;
                 
                if (empty($outputs))
                {
                    $backupClient = new SoapClient($backupURL);
                    $outputs = $client->ValidateCanadianAddressV2($params)->ValidateCanadianAddressV2Result;
                }

Address Validation Canada 2 RoR Rest Code Snippets

class RequestsController < ApplicationController
 
    def show
        @request = Request.find(params[:id])
        #Formats inputs into a hash to pass to Soap Client
        #Hash Keys must be named as they are shown here.
        message =   {                  
                    "Address" => @request.address1,
                    "Address2" => @request.address2,
                    "City" => @request.municipality,
                    "State" => @request.province,
                    "PostalCode" => @request.postalcode,
                    "Language" => @request.language,
                    "LicenseKey" => @request.licensekey,
                    }
        #Implemented to make the code more readable when accessing the hash        
        @avca2response = :validate_canadian_address_v2_response
        @avca2result = :validate_canadian_address_v2_result
        @avca2info = :canadian_address_info_v2
        @avca2error = :error
 
        #Set Primary and Backup URLs here as needed
        dotsAVCA2Primary = "https://trial.serviceobjects.com/avca2/api.svc?WSDL"
        dotsAVCA2Backup = "https://trial.serviceobjects.com/avca2/api.svc?WSDL"
 
        begin
            #initializes the soap client. The convert request keys global is necessary to receive a response from the service.
            client = Savon.client(  wsdl: dotsAVCA2Primary,
                                    element_form_default: :qualified,
                                    convert_request_keys_to: :camelcase
                                 )
            #Calls the operation with given inptus and converts response to a hash.
            response = client.call(:validate_canadian_address_v2, message: message).to_hash
 
            #Checks to see what results came back from the service
            processresults(response)           
             
        #If an error occurs during the call, this will use the backup url and attempt to retrieve data.
        rescue Savon::Error => e
            begin
            backupclient = Savon.client(    wsdl: dotsAVCA2Backup,
                                            element_form_default: :qualified,
                                            convert_request_keys_to: :camelcase
                                       )
            #Sets the response to the backclient call to the operation and converts response to a hash.
            response = backupclient.call(:validate_canadian_address_v2, message: message).to_hash
            processresults(response)
            end
        end
    end
    private
    def processresults(response)   
            #Processes Error Response from soap Client     
            #Processes Valid response from soap client 
         
    end
end

Address Validation Canada 2 Python Code Snippet

mAddress =  Address.get()
if mAddress is None or  mAddress == "":
     mAddress = " "
mAddress2 = Address2.get()
if mAddress2 is None or mAddress2 == "":
    mAddress2 = " "
mMunicipality = Municipality.get()
if mMunicipality is None or mMunicipality == "":
    mMunicipality = " "
mProvince = Province.get()
if mProvince is None or mProvince == "":
    mProvince = " "
mPostalCode = PostalCode.get()
if mPostalCode is None or mPostalCode == "":
    mPostalCode = " "
mLanguage = Language.get()
if mLanguage is None or mLanguage == "":
    mLanguage = " "
mLicenseKey = LicenseKey.get()
if mLicenseKey is None or mLicenseKey == "":
    mLicenseKey = " "
 
#Set the primary and backup URLs as needed
primaryURL = 'https://trial.serviceobjects.com/avca2/api.svc?WSDL'
backupURL = 'https://trial.serviceobjects.com/avca2/api.svc?WSDL'
 #This block of code calls the web service and prints the resulting values to the screen
try:
    client = Client(primaryURL)
    result = client.service.ValidateCanadianAddressV2(Address=mAddress, Address2=mAddress2, Municipality=mMunicipality, Province=mProvince, PostalCode=mPostalCode, Language=mLanguage, LicenseKey=mLicenseKey)
    #Handel response and check for errors
 
#Tries the backup URL if the primary URL failed
except:
    try:
        client = Client(backupURL)
        result = client.service.ValidateCanadianAddressV2(Address=mAddress, Address2=mAddress2, Municipality=mMunicipality, Province=mProvince, PostalCode=mPostalCode, Language=mLanguage, LicenseKey=mLicenseKey)
       #Handel response and check for errors
 
    #If the backup call failed then this will display an error to the screen
    except:
        Label(swin.window, text='Error').pack()
        print (result)

Address Validation 2 Canada Code Snippet

<!--Makes Request to web service --->
<cfscript>
        try
        {
            if (isDefined("form.Action") AND Action neq "")
            {
                wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/avca2/api.svc?WSDL");                          
                outputs = wsresponse.validateCanadianAddressV2("#Address#", "#Address2#", "#Municipality#", "#Province#", "#PostalCode#", "#Language#", "#LicenseKey#");
            }
        }
    catch(any Exception){
        try
            {
                if (isDefined("form.Action") AND Action neq "")
                {
                    wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/avca2/api.svc?WSDL");                          
                    outputs = wsresponse.validateCanadianAddressV2("#Address#", "#Address2#", "#Municipality#", "#Province#", "#PostalCode#", "#Language#", "#LicenseKey#");
                }
            }
            catch(any Exception)   
                {
                 writeoutput("An Error Has Occured. Please Reload and try again: #Exception.message#");             
                }
        }
</cfscript>

Address Validation 2 Canada Code Snippet

Try
    Dim ws As New AVCA2.ValidateCanada2Client
    Dim response As AVCA2.CanadianAddressResponseV2
    response = ws.ValidateCanadianAddressV2(Address.Text, Address2.Text, Municipality.Text, Province.Text, PostalCode.Text, Language.Text, LicenseKey.Text)
    If (response Is Nothing) Then
        ProcessValidResponse(response)
    Else
        ProcessErrorResponse(response.Error)
    End If
 
Catch er As Exception
    ''Set the Primary and Backup Service References as necessary
    Try
        Dim wsbackup As New AVCA2.ValidateCanada2Client
        Dim response As AVCA2.CanadianAddressResponseV2
        response = wsbackup.ValidateCanadianAddressV2(Address.Text, Address2.Text, Municipality.Text, Province.Text, PostalCode.Text, Language.Text, LicenseKey.Text)
        If (response.Error Is Nothing) Then
            ProcessValidResponse(response)
        Else
            ProcessErrorResponse(response.Error)
        End If
    Catch ex As Exception
        resultsLabel.Visible = True
        resultsLabel.Text = ex.Message
    End Try
End Try

Address Validation Canada 2 Apex Code Snippet

wwwServiceobjectsCom.CanadianAddressResponseV2 result;
try{
wwwServiceobjectsCom.DOTSAVCA2 client = new wwwServiceobjectsCom.DOTSAVCA2();
result = client.ValidateCanadianAddressV2([Address], [Address2], [Municipality], [Province], [PostalCode], [Language], [LicenseKey]);
}
catch(Exception ex){
 //If the first request failed try the failover endpoint
wwwServiceobjectsCom.DOTSAVCA2 backupClient = new wwwServiceobjectsCom.DOTSAVCA2();
//The backup environment will be provided to you upon purchasing a production license key
backupClient.endpoint_x = 'https://trial.serviceobjects.com/AVCA2/api.svc/soap';
result = backupClient.ValidateCanadianAddressV2([Address], [Address2], [Municipality], [Province], [PostalCode], [Language], [LicenseKey]);
}

Address Validation Canada 2 TSQL Code Snippet

SET @requestBody ='<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+
                   '<s:Body>'+
                   '<ValidateCanadianAddressV2 xmlns="https://www.serviceobjects.com">'+
                   '<Address>' + @address + '</Address>'+
                   '<Address2>' + @address2 + '</Address2>'+
                   '<Municipality>' + @municipality + '</Municipality>'+
                   '<Province>' + @province + '</Province>'+
                   '<PostalCode>' + @postalcode + '</PostalCode>'+
                   '<Language>' + @language + '</Language>'+
                   '<LicenseKey>' + @key + '</LicenseKey>'+
                   '</ValidateCanadianAddressV2>'+
                   '</s:Body>'+
                   '</s:Envelope>'
 
SET @requestLength = LEN(@requestBody)
 
    --If a production key is purchased, this will execute the failover
IF @isLiveKey = 1
BEGIN
    EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
    EXEC sp_OAMethod @obj, 'Open', NULL, 'POST', 'https://trial.serviceobjects.com/AVCA2/api.svc/soap', false
    EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'HOST', 'sws.serviceobjects.com'
    EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type', 'text/xml; charset=UTF-8'
    EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'SOAPAction', '"https://www.serviceobjects.com/IValidateCanada2/ValidateCanadianAddressV2"'
    EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Length', @requestLength
    EXEC sp_OAMethod @obj, 'send', NULL, @requestBody
    EXEC sp_OAGetProperty @obj, 'Status', @responseCode OUTPUT
    EXEC sp_OAGetProperty @obj, 'StatusText', @statusText OUTPUT
    EXEC sp_OAGetProperty @obj, 'responseText', @response OUTPUT
             
    --Checks the Response for a fatal error or if null.
    IF @response IS NULL
    BEGIN
        EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
        EXEC sp_OAMethod @obj, 'Open', NULL, 'POST', 'https://trial.serviceobjects.com/AVCA2/api.svc/soap', false
        EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'HOST', 'swsbackup.serviceobjects.com'
        EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type', 'text/xml; charset=UTF-8'
        EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'SOAPAction', '"https://www.serviceobjects.com/IValidateCanada2/ValidateCanadianAddressV2"'
        EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Length', @requestLength
        EXEC sp_OAMethod @obj, 'send', NULL, @requestBody
        EXEC sp_OAGetProperty @obj, 'Status', @responseCode OUTPUT
        EXEC sp_OAGetProperty @obj, 'StatusText', @statusText OUTPUT
        EXEC sp_OAGetProperty @obj, 'responseText', @response OUTPUT
    END
END

Address Validation Canada 2 NodeJS Code Snippet

SET @requestBody ='<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+
                   '<s:Body>'+
                   '<ValidateCanadianAddressV2 xmlns="https://www.serviceobjects.com">'+
                   '<Address>' + @address + '</Address>'+
                   '<Address2>' + @address2 + '</Address2>'+
                   '<Municipality>' + @municipality + '</Municipality>'+
                   '<Province>' + @province + '</Province>'+
                   '<PostalCode>' + @postalcode + '</PostalCode>'+
                   '<Language>' + @language + '</Language>'+
                   '<LicenseKey>' + @key + '</LicenseKey>'+
                   '</ValidateCanadianAddressV2>'+
                   '</s:Body>'+
                   '</s:Envelope>'
 
SET @requestLength = LEN(@requestBody)
 
    --If a production key is purchased, this will execute the failover
IF @isLiveKey = 1
BEGIN
    EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
    EXEC sp_OAMethod @obj, 'Open', NULL, 'POST', 'https://trial.serviceobjects.com/AVCA2/api.svc/soap', false
    EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'HOST', 'sws.serviceobjects.com'
    EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type', 'text/xml; charset=UTF-8'
    EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'SOAPAction', '"https://www.serviceobjects.com/IValidateCanada2/ValidateCanadianAddressV2"'
    EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Length', @requestLength
    EXEC sp_OAMethod @obj, 'send', NULL, @requestBody
    EXEC sp_OAGetProperty @obj, 'Status', @responseCode OUTPUT
    EXEC sp_OAGetProperty @obj, 'StatusText', @statusText OUTPUT
    EXEC sp_OAGetProperty @obj, 'responseText', @response OUTPUT
             
    --Checks the Response for a fatal error or if null.
    IF @response IS NULL
    BEGIN
        EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
        EXEC sp_OAMethod @obj, 'Open', NULL, 'POST', 'https://trial.serviceobjects.com/AVCA2/api.svc/soap', false
        EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'HOST', 'swsbackup.serviceobjects.com'
        EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Type', 'text/xml; charset=UTF-8'
        EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'SOAPAction', '"https://www.serviceobjects.com/IValidateCanada2/ValidateCanadianAddressV2"'
        EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'Content-Length', @requestLength
        EXEC sp_OAMethod @obj, 'send', NULL, @requestBody
        EXEC sp_OAGetProperty @obj, 'Status', @responseCode OUTPUT
        EXEC sp_OAGetProperty @obj, 'StatusText', @statusText OUTPUT
        EXEC sp_OAGetProperty @obj, 'responseText', @response OUTPUT
    END
END