Address GeoCode Canada C# Code Snippet

//Add a service to your application https://trial.serviceobjects.com/gcc/soap.svc?WSDL
GeoCoderCandada2Client GCCClient_Primary = new GeoCoderCandada2Client("DOTSGCC");
CanadianGeoCoderResponse response = GCCClient_Primary.GetGeoLocation(address, municipality, province, postalCode, LICENSE_KEY);
          
if (response.Error != null)
{
    //Process Error
}
else
{
    //Process Response     
}

Address GeoCode Canada Java Code Snippet

Location location= null;
  
Err error = null;
// Create soap request
DOTSGeoCoderCanadaLocator locator = new DOTSGeoCoderCanadaLocator();
// use ssl
locator.setDOTSGCCEndpointAddress("https://trial.serviceobjects.com/gcc/soap.svc?WSDL");
IGeoCoderCanada gcc= locator.getDOTSGCC();
DOTSGCCStub soap = (DOTSGCCStub)gcc;
soap.setTimeout(5000);
location= soap.getGeoLocation(address, municipality, province, postalCode, LICENSE_KEY);
  
error = location.getError();
if(resp == null || (error != null && error.getTypeCode() == "3"))
{
    throw new Exception();
}
   
//Process Results
if(error == null){
    //DOTS Address GeoCode Canada 2 Results
}
//Process Errors
else{
    //DOTS Address GeoCode Canada 2 Error Results  
}

Address GeoCode Canada PHP Code Snippet

<?php
// Set these values per web service <as needed>
$wsdlUrl = "https://trial.serviceobjects.com/gcc/soap.svc?WSDL";
  
$params['Address']      = $Address;
$params['Municipality'] = $Municipality;
$params['Province']     = $Province;
$params['PostalCode']   = $PostalCode;
$params['LicenseKey']   = $LicenseKey;
  
$soapClient = new SoapClient($wsdlUrl, array( "trace" => 1 ));
$result = $soapClient->GetGeoLocation($params);
if (!isset($result->GetGeoLocationResult->Error)) {
    foreach($result->GetGeoLocationResult->GeoLocationInfo as $k=>$v) {
        echo $k . ", " . $v;
    }
} else {
    foreach($result->GetGeoLocationResult->Error as $k=>$v) {
        echo $k . ", " . $v;
    }
}
?>

Address GeoCode Canada RoR Code Snippet

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.address,
                    "Municipality" => @request.municipality,
                    "Province" => @request.province,
                    "PostalCode" => @request.postalcode,
                    "LicenseKey" => @request.licensekey,
                    }
          
        #Implemented to make the code more readable when accessing the hash        
        @agcaresponse = :get_geo_location_response
        @agcaresult = :get_geo_location_result
        @agcaerror = :error
  
        #Set Primary and Backup URLs here as needed
        dotsAGCAPrimary = "https://trial.serviceobjects.com/gcc/soap.svc?WSDL"
        dotsAGCABackup = "https://trial.serviceobjects.com/gcc/soap.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: dotsAGCAPrimary,
                                    element_form_default: :qualified,
                                    convert_request_keys_to: :camelcase
                                 )
            #Calls the operation with given inptus and converts response to a hash.
            response = client.call(:get_geo_location, 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: dotsAGCABackup,
                                            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(:get_geo_location, 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 GeoCode Canada Python Code Snippet

mAddress =  Address.get()
 if mAddress is None or  mAddress == "":
      mAddress = " "
 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 = " "
 mLicenseKey = LicenseKey.get()
 if mLicenseKey is None or mLicenseKey == "":
     mLicenseKey = " "
 
 #Set the primary and backup URLs as needed
 primaryURL = 'https://trial.serviceobjects.com/gcc/soap.svc?WSDL'
 backupURL = 'https://trial.serviceobjects.com/gcc/soap.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.GetGeoLocation(Address=mAddress, Municipality=mMunicipality, Province=mProvince, PostalCode=mPostalCode, LicenseKey=mLicenseKey)
     #Loops through either the error result or proper result and displays values to the screen.
     if hasattr(result, 'Error') :
         for value in result.Error:
             Label(swin.window, text=str(value[0]) + " : " + str(value[1]) if value[1] else str(value[1])+": None").pack()
    #Handel response and check for errors
 
  #Tries the backup URL if the primary URL failed
 except:
     try:
         client = Client(backupURL)
         result = client.service.GetGeoLocation(Address=mAddress, Municipality=mMunicipality, Province=mProvince, PostalCode=mPostalCode, 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 GeoCode Canada ColdFusion Code Snippet

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

Address GeoCode Canada Visual Basic Code Snippet

Try
    Dim ws As New AGCA.DOTSGeoCoderCanadaSoapClient
    Dim response As AGCA.Location
    response = ws.GetGeoLocation(Address.Text, Municipality.Text, Province.Text, PostalCode.Text, LicenseKey.Text)
    If (response.Error Is Nothing) Then
        ProcessValidResponse(response)
    Else
        ProcessErrorResponse(response.Error)
    End If
Catch
    ''Set the Primary and Backup Service References as necessary
    Try
        Dim wsbackup As New AGCA.DOTSGeoCoderCanadaSoapClient
        Dim response As AGCA.Location
        response = wsbackup.GetGeoLocation(Address.Text, Municipality.Text, Province.Text, PostalCode.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 GeoCode Canada Apex Code Snippet

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

Address GeoCode Canada TSQL Code Snippet

SET @requestBody ='<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+
                   '<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+
                   '<GetGeoLocation xmlns="https://www.serviceobjects.com/">'+
                   '<Address>' + @address + '</Address>'+
                   '<Municipality>' + @municipality + '</Municipality>'+
                   '<Province>' + @province + '</Province>'+
                   '<PostalCode>' + @postalcode + '</PostalCode>'+
                   '<LicenseKey>' + @key + '</LicenseKey>'+
                   '</GetGeoLocation>'+
                   '</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/gcc/', 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/GetGeoLocation"'
    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/gcc/', 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/GetGeoLocation"'
        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 GeoCode Canada NodeJS Code Snippet

var args = {Address: 'Address',
            Municipality: 'Municipality',
            Province: 'Province',
            PostalCode: 'PostalCode',
            LicenseKey: 'LicenseKey'};
soap.createClient(primaryUrl, function(err, client) {
      
    client.GetGeoLocation(args, function(err, result) {
        //This is where you will handle the service results. Your business logic will determine
        //how the validated information is used.
        //The exact output can be found in our documentation:
        //https://test.serviceobjects.com/docs/dots-address-geocode-canada/
        if(err != null || result == null)
        {
            //There was an error that occurred that wasn't part of the normal service response
            return;
        }
        else{
            //Check for an error object
            if(result.GetGeoLocationResult.Error != null)
            {
                //An error object was returned by the service and you will want to use
                //the following failover logic.
                //If it was a Service Objects Fatal exception we recommend trying
                //a backup server.
                if(result.GetGeoLocationResult.Error.Number == "4")
                {
                    //The actual backup url will be provided when you purchase a license key
                    var backupUrl = 'https://trial.serviceobjects.com/gcc/soap.svc?WSDL';
                    soap.createClient(backupUrl, function(failoverErr, backupClient) {
      
                        backupClient.GetGeoLocation(args, function(failoverErr, failoverResult) {
                            //Handle the failoverErr or failoverResult objects.
                            return;
                        });
                    });
                }
                else{
                    //The Error object isn't of the type "Service Objects Fatal" so
                    //there is no need to use the failover logic. There was some Error of
                    //type Authorization, User Input, or Domain Specific.
                    response.writeHead(200, "OK", {'Content-Type': 'text/html'});
                    response.end(JSON.stringify(result));
                    return;
                }
            }
            else{
                //You have a non Error response.
                //All of the data will reside within the result object
                //As an easy to see what the service returns I am returning a JSON
                //serialized version as the response.
                response.writeHead(200, "OK", {'Content-Type': 'text/html'});
                response.end(JSON.stringify(result));
                return;
            }
        }
        });
});