Name Validation 2 C# Code Snippet

//Add a service to your application https://trial.serviceobjects.com/nv2/api.svc
NV2Client = new NV2LibraryClient("DOTSNameValidation2Primary");
NV2Client.InnerChannel.OperationTimeout = new TimeSpan(0, 0, 0, WEB_SERVICE_REQUEST_TIMEOUT);
response = NV2Client.ValidateNameV2(name, option, licenseKey);
//NULL ERROR || FATAL ERROR RETURNED -- TRY BACKUP
if (response == null || (response.Error != null && response.Error.TypeCode == "3"))
{
    //Call Backup Endpoint
}
return response;

Name Validation 2 Java Code Snippet

NameInfoV2Response  NV2Response = null;
NV2Error error= null;
String name = request.getParameter("iName");
String option = request.getParameter("iOption");
String licenseKey = request.getParameter("iKey");
             
NameValidation2Locator locator = new NameValidation2Locator();
 
locator.setEndpointAddress("soap", "https://trial.serviceobjects.com/NV2/api.svc/soap");
 
INV2Library soap = locator.getsoap();
 
try{
    NV2Response = soap.validateNameV2(name, option, licenseKey);
     
    error = NV2Response.getError();
    if(error !=null && error.getTypeCode() == "3")
    {
        throw new Exception(); 
    }
    }
catch
{
    //call backup endpoint
}

Name Validation 2 PHP Code Snippet

<?php
 
// Only make Soap request or show the results table if the form was submitted.
if (($Action)=="Submit") {
 
// Invoke the operation
    $SoapResponse =
        $soapClient->ValidateNameV2(array(
        "Name" => $Name,
        "Option" => $Option,
        "LicenseKey" => $LicenseKey));
 
    //Store result node in a more convenient variable
    $ResultNode = $SoapResponse->ValidateNameV2Result;
 
    ?>

Name Validation 2 RoR Code Snippet

#Implemented to make the code more readable when accessing the hash    
@nv2response = :validate_name_v2_response
@nv2result = :validate_name_v2_result
@nv2info = :name_info_v2
@nv2error = :error
 
#Set Primary and Backup URLs here as needed
dotsNV2Primary = "https://trial.serviceobjects.com/nv2/api.svc?WSDL"
dotsNV2Backup = "https://trial.serviceobjects.com/nv2/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: dotsNV2Primary,
              element_form_default: :qualified,
              convert_request_keys_to: :camelcase
             )
  #Calls the operation with given inptus and converts response to a hash.
  response = client.call(:validate_name_v2, 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: dotsNV2Backup,
                  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(:validate_name_v2, 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

Name Validation 2 Python Code Snippet

#Set the primary and backup URLs as needed
primaryURL = 'https://trial.serviceobjects.com/NV2/api.svc?wsdl'
backupURL = 'https://trial.serviceobjects.com/NV2/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.ValidateNameV2(Name= mName, Option=mOption, 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 str(value[1]) else str(value[0])+": None").pack()
 
    else:
        #Prints all the values in a successful response except for BestGuessName
        for value in result.NameInfoV2:
            if str(value[0]) != 'BestGuessName':
                Label(swin.window, text=(str(value[0]) + ":  " + str(value[1]) if (str(value[1]) != "None") else str(value[0]) + " : None")).pack()
 
        if str(result.NameInfoV2.BestGuessName) != "None":
                Label(swin.window, font ='bold', text="Best Guess Name").pack()
                for value in result.NameInfoV2.BestGuessName:
                    Label(swin.window, text=str(value[0]) + ":  " + str(value[1]) if (str(value[1]) != "None") else str(value[0]) + " : None").pack()
 
#Tries the backup URL if the primary URL failed
except:
    try:
        client = Client(backupURL)
        result = client.service.ValidateNameV2(Name= mName, Option=mOption, 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 str(value[1]) else str(value[0])+": None").pack()

Name Validation 2 Code Snippet

<!--Makes Request to web service --->
<cfscript>
        try
        {
            if (isDefined("form.Action") AND Action neq "")
            {
                wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/NV2/api.svc?wsdl");                             
                outputs = wsresponse.validateNameV2("#Name#", "#Option#", "#LicenseKey#");
            }
        }
    catch(any Exception){
        try
            {
                if (isDefined("form.Action") AND Action neq "")
                {
                    wsresponse = CreateObject("webservice", "https://trial.serviceobjects.com/NV2/api.svc?wsdl");                             
                    outputs = wsresponse.validateNameV2("#Name#", "#Option#", "#LicenseKey#");
                     
                }
            }
            catch(any Exception)    {
                 writeoutput("An Error Has Occured. Please Reload and try again");              
                }
        }
</cfscript>

Name Validation 2 Visual Basic Code Snippet

Try
    Dim ws As New NV2ServiceReference.NV2LibraryClient
    Dim response As NV2ServiceReference.NameInfoV2Response
 
 
    response = ws.ValidateNameV2(Name.Text, Opt.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 NV2ServiceReference.NV2LibraryClient
        Dim response As NV2ServiceReference.NameInfoV2Response
 
        response = wsbackup.ValidateNameV2(Name.Text, Opt.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

Name Validation 2 Apex Code Snippet

wwwServiceobjectsCom.NameInfoV2Response result;
try{
wwwServiceobjectsCom.soap client = new wwwServiceobjectsCom.soap();
result = client.ValidateNameV2([Name], [Option], [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/NV2/api.svc/soap';
result = backupClient.ValidateNameV2([Name], [Option], [LicenseKey]);
}

Name Validation 2 TSQL Code Snippet

SET @requestBody = '<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">'+
                   '<s:Body>'+
                   '<ValidateNameV2 xmlns="https://www.serviceobjects.com">'+
                   '<Name>' + @name + '</Name>'+
                   '<Option>' + @option + '</Option>'+
                   '<LicenseKey>' + @key + '</LicenseKey>'+
                   '</ValidateNameV2>'+
                   '</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/NV2/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/INV2Library/ValidateNameV2"'
    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/NV2/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/INV2Library/ValidateNameV2"'
        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