- C#
- Java
- PHP
- RoR
- Python
- ColdFusion
- VB
- Apex
- TSQL
- NodeJS
Phone Append 2 C# Code Snippet
//Add a service to your application https://trial.serviceobjects.com/pa2/api.svc/soap PhoneAppend2Client PA2Client_Primary = new PhoneAppend2Client("DOTSPA2"); PhoneInfoResponse response = PA2Client_Primary.CompositePhoneAppend(inputName, inputAddress, inputCity, inputState, inputZip, inputIsBusiness, inputLicenseKey); if (response.Error != null) { //Process Error } else { //Process Response }
Phone Append 2 Java Code Snippet
Location location= null; Err error = null; // Create soap request PhoneAppend2Locator locator = new PhoneAppend2Locatorlocator(); // use ssl locator.setDOTSPhoneAppend2EndpointAddress("https://trial.serviceobjects.com/pa2/api.svc/soap"); IPhoneAppend2 pa= locator.getDOTSPhoneAppend2(); DOTSPhoneAppend2Stub soap = (DOTSPhoneAppend2Stub) pa; soap.setTimeout(5000); location= soap.phoneAppend_GETXML(fullName, firstName, lastName, address, city, state, postalCode, licenseKey); error = location.getError(); if(resp == null || (error != null && error.getTypeCode() == "3")) { throw new Exception(); } //Process Results if(error == null){ //DOTS Phone Append 2 Results } //Process Errors else{ //DOTS Phone Append 2 Error Results }
Phone Append 2 PHP Code Snippets
<?php // Set these values per web service <as needed> $wsdlUrl = "https://trial.serviceobjects.com/pa2/api.svc?wsdl"; $params['Name'] = $Name; $params['Address'] = $Address; $params['City'] = $City; $params['State'] = $State; $params['PostalCode'] = $PostalCode; $params['isBusiness'] = $isBusiness; $params['LicenseKey'] = $LicenseKey; $soapClient = new SoapClient($wsdlUrl, array( "trace" => 1 )); $result = $soapClient->CompositePhoneAppend($params); if (!isset($result->CompositePhoneAppendResult->Error)) { foreach($result->CompositePhoneAppendResult->PhoneInfoas $k=>$v) { echo $k . ", " . $v; } } else { foreach($result->CompositePhoneAppendResult->Error as $k=>$v) { echo $k . ", " . $v; } } ?>
Phone Append 2 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 = { "FullName" => @request.fullname, "FirstName" => @request.firstname, "LastName" => @request.lastname, "Address" => @request.address, "City" => @request.city, "State" => @request.state, "PostalCode" => @request.postalcode, "LicenseKey" => @request.licensekey, } #Implemented to make the code more readable when accessing the hash @pa2response = :phone_append_response @pa2result = :phone_append_result @pa2info = :phone_info @pa2error = :error #Set Primary and Backup URLs here as needed dotsPA2Primary = "https://trial.serviceobjects.com/pa2/api.svc?WSDL" dotsPA2Backup = "https://trial.serviceobjects.com/pa2/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: dotsPA2Primary) #Calls the operation with given inptus and converts response to a hash. response = client.call(:phone_append, 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: dotsPA2Backup) #Sets the response to the backclient call to the operation and converts response to a hash. response = backupclient.call(:phone_append, message: message).to_hash processresults(response) #If backup url failed, this will display the error received from the server rescue Savon::Error =>error end end end private def processresults(response) #Processes Error Response from soap Client #Processes Valid response from soap client end
Phone Append 2 Python Code Snippet
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 = " " mAddress = Address.get() if mAddress is None or mAddress == "": mAddress = " " 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 = " " mLicenseKey = LicenseKey.get() if mLicenseKey is None or mLicenseKey == "": mLicenseKey = " " #Set the primary and backup URLs as needed primaryURL = 'https://trial.serviceobjects.com/pa2/api.svc?WSDL' backupURL = 'https://trial.serviceobjects.com/pa2/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.PhoneAppend(FullName= mFullName, FirstName= mFirstName, LastName=mLastName, Address= mAddress, City= mCity, State= mState, PostalCode= mPostalCode, 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.PhoneAppend(FullName= mFullName, FirstName= mFirstName, LastName=mLastName, Address= mAddress, City= mCity, State= mState, 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)
Phone Append 2 ColdFusion Code Snippet
<!--Makes Request to web service ---> <cfscript> try { if (isDefined("form.Action") AND Action neq "") { wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/pa2/api.svc?WSDL"); outputs = wsresponse.phoneAppend("#FullName#", "#FirstName#", "#LastName#", "#Address#", "#City#", "#State#", "#PostalCode#" ,"#LicenseKey#"); writedump(outputs.getPhoneInfo()); } } catch(any Exception) { try { if (isDefined("form.Action") AND Action neq "") { wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/pa2/api.svc?WSDL"); outputs = wsresponse.phoneAppend("#FullName#", "#FirstName#", "#LastName#", "#Address#", "#City#", "#State#", "#PostalCode#" ,"#LicenseKey#"); } } catch(any Exception) { writeoutput("An Error Has Occured. Please Reload and try again #Exception.message#"); } } </cfscript>
Phone Append 2 VB Code Snippet
Try Dim ws As New PA2.PhoneAppend2Client Dim response As PA2.PhoneInfoResponse response = ws.PhoneAppend(FullName.Text, FirstName.Text, LastName.Text, Address.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 Try ''Set the primary and backup service references as necessary Dim wsbackup As New PA2.PhoneAppend2Client Dim response As PA2.PhoneInfoResponse response = wsbackup.PhoneAppend(FullName.Text, FirstName.Text, LastName.Text, Address.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
Phone Append 2 Apex Code Snippet
wwwServiceobjectsCom.PhoneInfoResponse result; try{ wwwServiceobjectsCom.soap client = new wwwServiceobjectsCom.soap(); result = client.PhoneAppend([FullName], [FirstName], [LastName], [Address], [City], [State, [ZipCode], [LicenseKey]); } catch(Exception ex){ //If the first request failed try the failover endpoint wwwServiceobjectsCom.soap backupClient = new wwwServiceobjectsCom.soap(); //The backup environment will be provided to you upon purchasing a production license key backupClient.endpoint_x = 'https://trial.serviceobjects.com/PA2/api.svc/soap'; result = backupClient.PhoneAppend([FullName], [FirstName], [LastName], [Address], [City], [State, [ZipCode], [LicenseKey]); }
Phone Append 2 TSQL Code Snippet
SET @requestBody = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' + '<s:Body>' + '<PhoneAppend xmlns="https://www.serviceobjects.com">' + '<FullName>' + @fullname + '</FullName>' + '<FirstName>' + @firstname + '</FirstName>' + '<LastName>' + @lastname + '</LastName>' + '<Address>' + @address + '</Address>' + '<City>' + @city + '</City>' + '<State>' + @state + '</State>' + '<PostalCode>' + @postalcode + '</PostalCode>' + '<LicenseKey>' + @key + '</LicenseKey>' + '</PhoneAppend>' + '</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://sws.serviceobjects.com/PA2/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/IPhoneAppend2/PhoneAppend"' 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://swsbackup.serviceobjects.com/PA2/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/IPhoneAppend2/PhoneAppend"' 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
Phone Append 2 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://test.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; } } }); });