- C#
- Java
- PHP
- RoR
- Python
- ColdFusion
- VB
- Apex
- TSQL
- NodeJS
Address Detective C# Code Snippet
private FixedAddressResponse FindAddress(string Address1, string Address2, string City, string State, string PostalCode, string BusinessName, string PhoneNumber, string FullName, string FirstName, string LastName, string LicenseKey) { // addressValidation is a proxy used to simplify calls to the web-service AddressDetectiveClient ADClient_Primary = null; AddressDetectiveClient ADClient_Backup = null; FixedAddressResponse response = null; try { ADClient_Primary = new AddressDetectiveClient("DOTSAddressDetectivePrimary"); ADClient_Primary.InnerChannel.OperationTimeout = new TimeSpan(0, 0, 0, WEB_SERVICE_REQUEST_TIMEOUT); response = ADClient_Primary.FindAddress(Address1, Address2, City, State, PostalCode, BusinessName, PhoneNumber, FullName, FirstName, LastName, LicenseKey); //NULL ERROR || FATAL ERROR RETURNED -- TRY BACKUP if (response == null || (response.Error != null && response.Error.TypeCode == "3")) { throw new Exception(); } return response; } catch (Exception) { try { //Use swsbackup client on backup ADClient_Backup = new AddressDetectiveClient("DOTSAddressDetectiveBackup"); ADClient_Backup.InnerChannel.OperationTimeout = new TimeSpan(0, 0, 0, WEB_SERVICE_REQUEST_TIMEOUT); return ADClient_Backup.FindAddress(Address1, Address2, City, State, PostalCode, BusinessName, PhoneNumber, FullName, FirstName, LastName, LicenseKey); } catch (Exception e) { throw e; } finally { if (ADClient_Backup != null) { ADClient_Backup.Close(); } } } finally { if (ADClient_Primary != null) { ADClient_Primary.Close(); } } } private void ProcessResponse(FixedAddressResponse response) { try { if (response.Error != null) { ProcessErrorResult(response.Error); } else { ProcessFindAddressResult(response); } }
Address Detective Java Code Snippet
FixedAddress[] addresses = null; ADError error= null; String address1 = request.getParameter("iAddr1"); String address2 = request.getParameter("iAddr2"); String city = request.getParameter("iCity"); String state = request.getParameter("iState"); String postalCode = request.getParameter("iPostal"); String businessName = request.getParameter("iBusinessName"); String phoneNumber = request.getParameter("iPhoneNumber"); String fullName = request.getParameter("iFullName"); String firstName = request.getParameter("iFirstName"); String lastName = request.getParameter("iLastName"); String licenseKey = request.getParameter("iKey"); IAddressDetectiveProxy locator = new IAddressDetectiveProxy(); //use ssl locator.setEndpoint("https://trial.serviceobjects.com/ad/api.svc/soap"); IAddressDetective ad = locator.getIAddressDetective(); DOTSAddressDetectiveStub soap = (DOTSAddressDetectiveStub)ad; soap.setTimeout(5000); try{ fixedAddressResponse = soap.findAddress(address1, address2, city, state, postalCode, businessName, phoneNumber, fullName, firstName, lastName, licenseKey); addresses = fixedAddressResponse.getAddresses(); error = fixedAddressResponse.getError(); if(error !=null && error.getTypeCode() == "3") { throw new Exception(); } } catch(Exception e) { //FAILOVER- USE BACKUP NOW try{ //CALL SOAP USING BACKUP URL (Change the endpoint) fixedAddressResponse = soap.findAddress(address1, address2, city, state, postalCode, businessName, phoneNumber, fullName, firstName, lastName, licenseKey); addresses = fixedAddressResponse.getAddresses(); error = fixedAddressResponse.getError(); } //DOTS Address Detective Results } else { //DOTS Address Detective Error }
Address Detective PHP Code Snippet
<?php $Address1 = trim($Address1); $Address2 = trim($Address2); $City = trim($City); $State = trim($State); $PostalCode = trim($PostalCode); $BusinessName = trim($BusinessName); $PhoneNumber = trim($PhoneNumber); $FullName = trim($FullName); $FirstName = trim($FirstName); $LastName = trim($LastName); $LicenseKey = trim($LicenseKey); $wsdlUrl = "https://trial.serviceobjects.com/ad/api.svc?wsdl"; try{ $soapClient = new SoapClient($wsdlUrl, array( "trace" => 1 )); $result = $soapClient->FindAddress($params); } catch(Exception $e) { try { $soapClient = new SoapClient($backupWsdlUrl, array( "trace" => 1 )); $result = $soapClient->FindAddress($params); } catch(Exception $ex) {//Both soap calls failed echo "<b> Primary and backup wsdls failed </b>"; echo "$ex"; } } if (!isset($result->FindAddressResult->Error)) { //Process AD Result } else { //Process AD Error } } ?>
Address Detective 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 = { "Address1" => @request.address1, "Address2" => @request.address2, "City" => @request.city, "State" => @request.state, "PostalCode" => @request.postalcode, "BusinessName" => @request.businessname, "PhoneNumber" => @request.phonenumber, "FullName" => @request.fullname, "FirstName" => @request.firstname, "LastName" => @request.lastname, "LicenseKey" => @request.licensekey, } #Implemented to make the code more readable when accessing the hash @adresponse = :find_address_response @adresult = :find_address_result @addresses = :addresses @adfixed = :fixed_address @aderror = :error #Set Primary and Backup URLs here as needed dotsADPrimary = "https://trial.serviceobjects.com/ad/api.svc?singleWsdl" dotsADBackup = "https://trial.serviceobjects.com/ad/api.svc?singleWsdl" begin #initializes the soap client. The convert request keys global is necessary to receive a response from the service. client = Savon.client( wsdl: dotsADPrimary, element_form_default: :qualified, convert_request_keys_to: :camelcase ) #Calls the operation with given inptus and converts response to a hash. response = client.call(:find_address, 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 backupurl and attempt to retrieve data. rescue Savon::Error => e begin backupclient = Savon.client( wsdl: dotsADBackup, 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(:find_address, 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 end
Address Detective Python Code Snippet
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 = " " mPostalCode = PostalCode.get() if mPostalCode is None or mPostalCode == "": mPostalCode = " " mBusinessName = BusinessName.get() if mBusinessName is None or mBusinessName == "": mBusinessName = " " mPhoneNumber = PhoneNumber.get() if mPhoneNumber is None or mPhoneNumber == "": mPhoneNumber = " " mFullName = FullName.get() if mFullName is None or mFullName == "": mFullName = " " mFirstName = FirstName.get() if mFirstName is None or mFirstName == "": mFirstName = " " mLastName = LastName.get() if mLastName is None or mLastName == "": mLastName = " " mLicenseKey = LicenseKey.get() if mLicenseKey is None or mLicenseKey == "": mLicenseKey = " " #Set the primary and backup URLs as needed primaryURL = 'https://trial.serviceobjects.com/ad/api.svc?wsdl' backupURL = 'https://trial.serviceobjects.com/ad/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.FindAddress(Address1=mAddress1, Address2=mAddress2, City=mCity, State=mState, PostalCode=mPostalCode, BusinessName=mBusinessName, PhoneNumber=mPhoneNumber, FullName=mFullName, FirstName=mFirstName, LastName=mLastName, LicenseKey=mLicenseKey) #Handel response from the service #Tries the backup URL if the primary URL failed except: try: client = Client(primaryURL) result = client.service.FindAddress(Address1=mAddress1, Address2=mAddress2, City=mCity, State=mState, PostalCode=mPostalCode, BusinessName=mBusinessName, PhoneNumber=mPhoneNumber, FullName=mFullName, FirstName=mFirstName, LastName=mLastName, LicenseKey=mLicenseKey) #Handel response from the service #If the backup call failed then this will display an error to the screen except: Label(swin.window, text='Error').pack() print (result)
Address Detective Code Snippet
<!--Makes Request to web service ---> <cfscript> try { if (isDefined("form.Action") AND Action neq "") { wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/ad/api.svc?singleWsdl"); outputs = wsresponse.findAddress("#Address1#", "#Address2#", "#City#", "#State#", "#PostalCode#", "#BusinessName#", "#PhoneNumber#", "#FullName#", "#FirstName#", "#LastName#", "#LicenseKey#"); } } catch(any error){ try { if (isDefined("form.Action") AND Action neq "") { wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/ad/api.svc?singleWsdl"); outputs = wsresponse.findAddress("#Address1#", "#Address2#", "#City#", "#State#", "#PostalCode#", "#BusinessName#", "#PhoneNumber#", "#FullName#", "#FirstName#", "#LastName#", "#LicenseKey#"); } } catch(any Exception) { writeoutput("An Error Has Occured. Please Reload and try again"); } } </cfscript>
Address Detective Visual Basic Code Snippet
Try Dim ws As New AD.AddressDetectiveClient Dim response As AD.FixedAddressResponse response = ws.FindAddress(Address1.Text, Address2.Text, City.Text, State.Text, PostalCode.Text, BusinessName.Text, PhoneNumber.Text, FullName.Text, FirstName.Text, LastName.Text, LicenseKey.Text) If (response.Error Is Nothing) Then ProcessValidResponse(response.Addresses(0)) Else ProcessErrorResponse(response.Error) End If Catch er As Exception ''Set the Primary and Backup Service References as necessary Try Dim wsbackup As New AD.AddressDetectiveClient Dim response As AD.FixedAddressResponse response = wsbackup.FindAddress(Address1.Text, Address2.Text, City.Text, State.Text, PostalCode.Text, BusinessName.Text, PhoneNumber.Text, FullName.Text, FirstName.Text, LastName.Text, LicenseKey.Text) If (response.Error Is Nothing) Then ProcessValidResponse(response.Addresses(0)) Else ProcessErrorResponse(response.Error) End If Catch ex As Exception resultsLabel.Visible = True resultsLabel.Text = ex.Message End Try End Try
Address Detective Apex Code Snippet
wwwServiceobjectsCom.FixedAddressResponse result; try{ wwwServiceobjectsCom.DOTSAddressDetective client = new wwwServiceobjectsCom.DOTSAddressDetective(); result = client.FindAddress([Address], [Address2], [City], [State], [PostalCode], [BusinessName], [PhoneNumber], [FullName], [FirstName], [LastName], [LicenseKey]); } catch(Exception ex){ //If the first request failed try the failover endpoint wwwServiceobjectsCom.DOTSAddressDetective backupClient = new wwwServiceobjectsCom.DOTSAddressDetective(); //The backup environment will be provided to you upon purchasing a production license key backupClient.endpoint_x = 'https://trial.serviceobjects.com/AD/api.svc/soap'; result = backupClient.FindAddress([Address], [Address2], [City], [State], [PostalCode], [BusinessName], [PhoneNumber], [FullName], [FirstName], [LastName], [LicenseKey]); }
Address Detective TSQL Code Snippet
SET @requestBody ='<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">'+ '<s:Body>'+ '<FindAddress xmlns="https://www.serviceobjects.com">'+ '<Address1>' + @address1 + '</Address1>'+ '<Address2>' + @address2 + '</Address2>'+ '<City>' + @city + '</City><State>' + @state + '</State>'+ '<PostalCode>' + @postalcode + '</PostalCode>'+ '<PhoneNumber>'+ @phonenumber + '</PhoneNumber>'+ '<FullName>'+ @fullname + '</FullName>'+ '<FirstName>'+ @firstname + '</FirstName>'+ '<LastName>'+ @lastname + '</LastName>'+ '<LicenseKey>' + @key + '</LicenseKey>'+ '</FindAddress>'+ '</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/AD/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/IAddressDetective/FindAddress"' 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/AD/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/IAddressDetective/FindAddress"' 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 Detective NodeJS Code Snippet
var args = {Address1: 'Address1', Address2: 'Address2', City: 'City', State: 'State', PostalCode: 'PostalCode', BusinessName: 'BusinessName', PhoneNumber: 'PhoneNumber', FullName: 'FullName', FirstName: 'FirstName', LastName: 'LastName', LicenseKey: 'Your-License-Key'}; soap.createClient(primaryUrl, function(err, client) { client.FindAddress(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-detective/ 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.FindAddressResult.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.FindAddressResult.Error.TypeCode == "3") { //The actual backup url will be provided when you purchase a license key var backupUrl = 'https://trial.serviceobjects.com/ad/api.svc?singleWsdl'; soap.createClient(backupUrl, function(failoverErr, backupClient) { backupClient.FindAddress(args, function(failoverErr, failoverResult) { //Handle the failoverErr or failoverResult objects. return; }); }); } } } }