- C#
- Java
- PHP
- RoR
- Python
- ColdFusion
- VB
- Apex
- TSQL
IP Address Validation C# Code Snippet
//Add a service to your application https://trial.serviceobjects.com/gpp/soap.svc?wsdl DOTSGeoPinPoint = new DOTSGeoPinPoint("DOTSGPP"); response = DOTSGeoPinPoint.GetLocationByIP_V2(IPAddress, licenseKey); if (response.Error != null) { //Process Error } else { //Process Response }
IP Address Validation Java Code Snippet
IP result = null; Error error = null; // Create soap request DOTSGeoPinPointLocator locator = new DOTSGeoPinPointLocator(); // use ssl locator.setDOTSGeoPinPointSoapEndpointAddress("https://trial.serviceobjects.com/gpp/soap.svc?wsdl"); DOTSGeoPinPointSoap gpp = locator.getDOTSGeoPinPointSoap(); DOTSGeoPinPointStub soap = (DOTSGeoPinPointStub)gpp; soap.setTimeout(5000);// set timeout result = soap.getLocationByIP_V2(ip, key); error = result.getError(); if(resp == null || (error != null && error.getTypeCode() == "3")) { throw new Exception(); } //Process Results if(error == null){ //DOTS IP Address Validation Results } //Process Errors else{ //DOTS IP Address Validation Error Results }
IP Address Validation PHP Code Snippet
<?php // Set these values per web service <as needed> $wsdlUrl = "https://trial.serviceobjects.com/gpp/soap.svc?wsdl"; $params['IPAddress'] = $IPAddress; $params['LicenseKey'] = $LicenseKey; $soapClient = new SoapClient($wsdlUrl, array( "trace" => 1 )); $result = $soapClient->GetLocationByIP_V2($params); if (!isset($result->GetLocationByIP_V2Result->Error)) { foreach($result->GetLocationByIP_V2Result as $k=>$v) { echo $k . ", " . $v; } } else { foreach($result->GetLocationByIP_V2Result->Error as $k=>$v) { echo $k . ", " . $v; } } ?>
IP Address Validation RoR Code Snippet
#Formats inputs into a hash to pass to Soap Client #Hash Keys must be named as they are shown here. message = { "IPAddress" => @request.ipaddress, "LicenseKey" => @request.licensekey, } #Implemented to make the code more readable when accessing the hash @ipavresponse = :get_location_by_ip_v4_response @ipavresult = :get_location_by_ip_v4_result @ipaverror = :error #Set Primary and Backup URLs here as needed dotsIPAVPrimary = "https://trial.serviceobjects.com/gpp/soap.svc?wsdl" dotsIPAVBackup = "https://trial.serviceobjects.com/gpp/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: dotsIPAVPrimary) #Calls the operation with given inptus and converts response to a hash. response = client.call(:get_location_by_ip_v4, 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: dotsIPAVBackup) #Sets the response to the backclient call to the operation and converts response to a hash. response = backupclient.call(:get_location_by_ip_v4, 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 end
IP Address Validation Python Code Snippet
mIPAddress = IPAddress.get() if mIPAddress is None or mIPAddress == "": mIPAddress = " " mLicenseKey = LicenseKey.get() if mLicenseKey is None or mLicenseKey == "": mLicenseKey = " " #Set the primary and backup URLs as needed primaryURL = 'https://trial.serviceobjects.com/gpp/soap.svc?wsdl' backupURL = 'https://trial.serviceobjects.com/gpp/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.GetLocationByIP_V4(IPAddress= mIPAddress, 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.GetLocationByIP_V4(IPAddress= mIPAddress, 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)
IP Address Validation ColdFusion Code Snippet
<!--Makes Request to web service ---> <cfscript> try { if (isDefined("form.Action") AND Action neq "") { wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/gpp/soap.svc?wsdl"); outputs = wsresponse.getLocationByIP_V4("#IPAddress#", "#LicenseKey#"); writedump(outputs); } } catch(any Exception){ try { if (isDefined("form.Action") AND Action neq "") { wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/gpp/soap.svc?wsdl"); outputs = wsresponse.getLocationByIP_V4("#IPAddress#", "#LicenseKey#"); } } catch(any Exception) { writeoutput("An Error Has Occured. Please Reload and try again"); } } </cfscript>
IP Address Validation VB Code Snippet
Try Dim ws As New IPAV.DOTSGeoPinPointSoapClient Dim response As IPAV.IP4 response = ws.GetLocationByIP_V4(IPAddress.Text, LicenseKey.Text) If (response.Error Is Nothing) Then ProcessValidResponse(response) Else ProcessErrorResponse(response.Error) End If Catch er As Exception Try ''Set Primary and Backup service references as necessary Dim wsbackup As New IPAV.DOTSGeoPinPointSoapClient Dim response As IPAV.IP4 response = wsbackup.GetLocationByIP_V4(IPAddress.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
IP Address Validation Apex Code Snippet
wwwServiceobjectsCom.IP4 result; try{ wwwServiceobjectsCom.DOTSGeoPinPointSoap client = new wwwServiceobjectsCom.DOTSGeoPinPointSoap(); result = client.GetLocationByIP_V4([IPAddress], [LicenseKey]); } catch(Exception ex){ //If the first request failed try the failover endpoint wwwServiceobjectsCom.DOTSGeoPinPointSoap backupClient = new wwwServiceobjectsCom.DOTSGeoPinPointSoap(); //The backup environment will be provided to you upon purchasing a production license key backupClient.endpoint_x = 'https://trial.serviceobjects.com/GPP/api.svc/soap'; result = backupClient.GetLocationByIP_V4([IPAddress], [LicenseKey]); }
IP Address Validation 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">'+ '<GetLocationByIP_V4 xmlns="https://www.serviceobjects.com/">'+ '<IPAddress>' + @ipaddress + '</IPAddress>'+ '<LicenseKey>' + @key + '</LicenseKey>'+ '</GetLocationByIP_V4>'+ '</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/gpp/', 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/GetLocationByIP_V4"' 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/gpp/', 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/GetLocationByIP_V4"' 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