- C#
- Java
- PHP
- RoR
- Python
- ColdFusion
- VB
- Apex
- TSQL
- NodeJS
Address Validation 3 C# Code Snippet
//Add a service to your application https://trial.serviceobjects.com/av3/api.svc/ AV3Client_Primary = new AddressValidation3Client("DOTSAddressValidation3"); response = AV3Client_Primary.GetBestMatches(Business, Address, Address2, City, State, PostalCode, licenseKey); if (response.Error != null) { //Process Error } else { //Process Response }
Address Validation 3 Java Code Snippet
BestMatchesResponse bestMatchResponse = null; Address[] addresses = null; AV3Error error= null; // Create soap request AddressValidation3Locator locator = new AddressValidation3Locator(); //use ssl locator.setDOTSAddressValidation3EndpointAddress("https://trial.serviceobjects.com/AV3/api.svc/soap"); IAddressValidation3 av = locator.getDOTSAddressValidation3(); DOTSAddressValidation3Stub soap = (DOTSAddressValidation3Stub)av; soap.setTimeout(5000);// set timeout bestMatchResponse = soap.getBestMatches(business, address, address2, city, state, postalCode, licenseKey); addresses = bestMatchResponse.getAddresses(); error = bestMatchResponse.getError(); if(error != null && error.getTypeCode() == "3") { throw new Exception(); } //Process Results if(error == null){ //DOTS Address Validation Results } //Process Errors else{ //DOTS Address Validation Error Results }
Address Validation 3 PHP Code Snippets
<?php // Set these values per web service <as needed> $wsdlUrl = "https://trial.serviceobjects.com/AV3/api.svc?wsdl"; $params['Business'] = $Business; $params['Address'] = $Address; $params['Address2'] = $Address2; $params['City'] = $City; $params['State'] = $State; $params['PostalCode'] = $PostalCode; $params['LicenseKey'] = $LicenseKey; $soapClient = new SoapClient($wsdlUrl, array( "trace" => 1 )); $result = $soapClient->GetBestMatches($params); if (!isset($result->GetBestMatchesResult->Error)) { foreach($result->GetBestMatchesResult->Addresses as $k=>$v) { echo "<tr><td><b>$k</b></td><td>$v</td></tr>"; } } else { foreach($result->GetBestMatchesResult ->Error as $k=>$v) { echo "<tr><td><b>$k</b></td><td>$v</td></tr>"; } } ?>
Address Validation 3 RoR SOAP Code Snippets
#Formats inputs into a hash to pass to Soap Client #Hash Keys must be named as they are shown here. message = { "BusinessName" => @request.businessname, "Address" => @request.address1, "Address2" => @request.address2, "City" => @request.city, "State" => @request.state, "PostalCode" => @request.postalcode, "LicenseKey" => @request.licensekey, } #Implemented to make the code more readable when accessing the hash @av3response = :get_best_matches_response @av3result = :get_best_matches_result @av3info = :addresses @av3address = :address @av3error = :error #Set Primary and Backup URLs here as needed dotsAV3Primary = "https://trial.serviceobjects.com/av3/api.svc?wsdl" dotsAV3Backup = "https://trial.serviceobjects.com/av3/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: dotsAV3Primary, 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_best_matches, 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 backup url and attempt to retrieve data. rescue Savon::Error => e begin backupclient = Savon.client( wsdl: dotsAV3Backup, 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_best_matches, message: message).to_hash processresults(response) #If backup url failed, this will display the error received from the server rescue Savon::Error =>error @status = error @displaydata = {"error" => "A Big Error Occured"} end end end private def processresults(response) #Processes Error Response from soap Client #Processes Valid response from soap client end
Address Validation US 3 Python Code Snippet
mBusinessName = BusinessName.get() if mBusinessName is None or mBusinessName == "": mBusinessName = " " mAddress1 = Address1.get() if mAddress1 is None or mAddress1 == "": mAddress1 = " " mAddress2 = Address2.get() if mAddress2 is None or mAddress2 == "": mAddress2 = " " mCity = City.get() if mCity is None or mCity == "": mCity = " " mState = State.get() if mState is None or mState == "": mState = " " mZip = Zip.get() if mZip is None or mZip == "": mZip = " " mLicenseKey = LicenseKey.get() if mLicenseKey is None or mLicenseKey == "": mLicenseKey = " " #Set the primary and backup URLs as needed primaryURL = 'https://trial.serviceobjects.com/av3/api.svc?wsdl' backupURL = 'https://trial.serviceobjects.com/av3/api.svc?wsdl' #This block of code calls the web service and prints the resulting values to the screen try: client = Client(primaryURL) client.service result = client.service.GetBestMatches(BusinessName=mBusinessName, Address=mAddress1, Address2=mAddress2, City=mCity, State=mState, PostalCode=mZip, LicenseKey=mLicenseKey) #Handel response and check for errors #Tries the backup URL if the primary URL failed except: try: client = Client(backupURL) client.service result = client.service.GetBestMatches(BusinessName=mBusinessName, Address=mAddress1, Address2=mAddress2, City=mCity, State=mState, PostalCode=mZip, 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 3 ColdFusion Code Snippet
<!---Invoke Live webservice---> <cftry> <cfinvoke webservice="https://trial.serviceobjects.com/av3/api.svc?wsdl" method="getBestMatches" returnvariable="aBestMatchesResponse"> <cfinvokeargument name="businessName" value="#trim(BusinessName)#"/> <cfinvokeargument name="address" value="#trim(Address)#"/> <cfinvokeargument name="address2" value="#trim(Address)#"/> <cfinvokeargument name="city" value="#trim(City)#"/> <cfinvokeargument name="state" value="#trim(State)#"/> <cfinvokeargument name="postalCode" value="#trim(PostalCode)#"/> <cfinvokeargument name="licenseKey" value="#trim(LicenseKey)#"/> </cfinvoke> <cfcatch> <!---Fail Over to backup WSDL---> <cfinvoke webservice="https://trial.serviceobjects.com/av3/api.svc?wsdl" method="getBestMatches" returnvariable="aBestMatchesResponse"> <cfinvokeargument name="businessName" value="#trim(BusinessName)#"/> <cfinvokeargument name="address" value="#trim(Address)#"/> <cfinvokeargument name="address2" value="#trim(Address)#"/> <cfinvokeargument name="city" value="#trim(City)#"/> <cfinvokeargument name="state" value="#trim(State)#"/> <cfinvokeargument name="postalCode" value="#trim(PostalCode)#"/> <cfinvokeargument name="licenseKey" value="#trim(LicenseKey)#"/> </cfinvoke> </cfcatch> </cftry>
Address Validation 3 VB Code Snippet
Try Dim ws As New AV3.AddressValidation3Client Dim response As AV3.BestMatchesResponse response = ws.GetBestMatches(BusinessName.Text, Address1.Text, Address2.Text, City.Text, State.Text, PostalCode.Text, LicenseKey.Text) If (response.Error 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 AV3.AddressValidation3Client Dim response As AV3.BestMatchesResponse response = wsbackup.GetBestMatches(BusinessName.Text, Address1.Text, Address2.Text, City.Text, State.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 Validation 3 Apex Code Snippet
wwwServiceobjectsCom.BestMatchesResponse result; try{ wwwServiceobjectsCom.DOTSAddressValidation3 client = new wwwServiceobjectsCom.DOTSAddressValidation3(); client.endpoint_x = 'https://trial.serviceobjects.com/AV3/api.svc/soap'; result = client.GetBestMatches([BusinessName],[Address],[Address2],[City],[State],[PostalCode],[LicenseKey]); } catch(Exception ex){ //If the first request failed try the failover endpoint wwwServiceobjectsCom.DOTSAddressValidation3 backupClient = new wwwServiceobjectsCom.DOTSAddressValidation3(); //The backup environment will be provided to you upon purchasing a production license key backupClient.endpoint_x = 'https://trial.serviceobjects.com/AV3/api.svc/soap'; result = backupClient.GetBestMatches(([BusinessName],[Address],[Address2],[City],[State],[PostalCode],[LicenseKey]); }
Address Validation 3 TSQL Code Snippet
SET @requestBody ='<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+ '<s:Body>'+ '<GetBestMatches xmlns="https://www.serviceobjects.com">'+ '<BusinessName>'+ @businessname + '</BusinessName>'+ '<Address>' + @address + '</Address>'+ '<Address2>' + @address2 + '</Address2>'+ '<City>' + @city + '</City><State>' + @state + '</State>'+ '<PostalCode>' + @postalcode + '</PostalCode>'+ '<LicenseKey>' + @key + '</LicenseKey>'+ '</GetBestMatches>'+ '</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/AV3/api.svc/soap', false EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'HOST', 'trial.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/IAddressValidation3/GetBestMatches"' 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/AV3/api.svc/soap', false EXEC sp_OAMethod @obj, 'setRequestHeader', NULL, 'HOST', 'trial.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/IAddressValidation3/GetBestMatches"' 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 3 NodeJS Code Snippet
var args = {BusinessName: 'BusinessName', Address: 'Address', Address2: 'Address2', City: 'City', State: 'State', PostalCode: 'PostalCode', LicenseKey: 'Your-License-Key'}; soap.createClient(primaryUrl, function(err, client) { client.GetBestMatches(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://www.serviceobjects.com/docs/dots-address-validation-us-3/ 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.GetBestMatchesResult.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.GetBestMatchesResult.Error.TypeCode == "3") { //The actual backup url will be provided when you purchase a license key var backupUrl = 'https://trial.serviceobjects.com/av3/api.svc?wsdl'; soap.createClient(backupUrl, function(failoverErr, backupClient) { backupClient.GetBestMatches(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 result.GetBestMatchesResult //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; } } }); });