RecogniContact/Web - International Address Parser Web Service - C# demo
SOAP Methods
class ParsingResult
class VersionInfo
class LicenseInfo
class UsageStats
Exceptions
PHP demo
C# demo
Java demo

C# demo


This code shows how to use RecogniContact/Web in a C# project.

Demo project download

http://address-parser.com/DemoCSharp.zip

This demo project contains
  • a complete Microsoft Visual C# demo project ready to compile
  • an executable file ready to run (in folder /bin/Debug)

NOTE! You will need a valid RecogniContact license to run this demo.


Demo source code




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RecogniContactDemo.com.loquisoft.webservices;

namespace RecogniContactDemo
{
    public partial class RecogniContactDemoForm : Form
    {
        public RecogniContactDemoForm()
        {
            InitializeComponent();
        }

        private void log(string s) {
            outputTextBox.Text += s + "\r\n";
        }

        private void button1_Click(object sender, EventArgs e)
        {

            try
                {

                    //NOTE! To add RecogniContact to your own Microsoft Visual C# application, 
                    //select “Project” – “Add web reference” in Microsoft Visual Studio, 
                    //and specify the WSDL URL:
                    //http://loquisoft.net/cgi-bin/RecogniContactWebService.exe/wsdl/IRecogniContactWebService

                    outputTextBox.Text = "";
                    //----------------------------------------------------------------
                    // Create Web Service object
                    //----------------------------------------------------------------

                    IRecogniContactWebServiceservice RecogniContact = new IRecogniContactWebServiceservice();

                    //----------------------------------------------------------------
                    // Show License Information 
                    //----------------------------------------------------------------


                    LicenseInfo myLicenseInfo = RecogniContact.GetLicenseInfo(licenseKeyTextBox.Text);

                    log("LICENSE INFORMATION");

                    //license expiry date (as a string)
                    //empty string = no time limit
                    log("LicenseExpiryDateAsString= " + myLicenseInfo.LicenseExpiryDateAsString);

                    //permitted total number of parsing operations 
                    //0 = unlimited
                    log("MaxParsings=               " + myLicenseInfo.MaxParsings);

                    //permitted number of parsing operations per period of time
                    //0 = unlimited
                    log("MaxParsingsPerDay=         " + myLicenseInfo.MaxParsingsPerDay);
                    log("MaxParsingsPerWeek=        " + myLicenseInfo.MaxParsingsPerWeek);
                    log("MaxParsingsPerMonth=       " + myLicenseInfo.MaxParsingsPerMonth);
                    log("MaxParsingsPerQuarter=     " + myLicenseInfo.MaxParsingsPerQuarter);
                    log("MaxParsingsPerYear=        " + myLicenseInfo.MaxParsingsPerYear);

                    //IP addresses allowed to call RecogniContact web service
                    //Empty string = no limitation
                    log("CallerIPRange=             " + myLicenseInfo.CallerIPRange);

                    //licensed Parser countries 
                    //Empty string = no limitation
                    log("ParserCountries=           " + myLicenseInfo.ParserCountries);

                    //user name associated with license key
                    log("UserName=                  " + myLicenseInfo.UserName);

                    //Additional info about license owner
                    log("UserInfo=                  " + myLicenseInfo.UserInfo);


                    //----------------------------------------------------------------
                    // Show Usage Statistics 
                    //----------------------------------------------------------------

                    log("");
                    log("USAGE STATISTICS");

                    UsageStats myUsageStats = RecogniContact.GetUsageStats(licenseKeyTextBox.Text);

                    //total number of completed parsing operations so far
                    log("NumberParsings=            " + myUsageStats.NumberParsings);

                    //number of completed parisderng operations per period of time
                    log("NumberParsingsToday=       " + myUsageStats.NumberParsingsToday);
                    log("NumberParsingsThisWeek=    " + myUsageStats.NumberParsingsThisWeek);
                    log("NumberParsingsThisMonth=   " + myUsageStats.NumberParsingsThisMonth);
                    log("NumberParsingsThisQuarter= " + myUsageStats.NumberParsingsThisQuarter);
                    log("NumberParsingsThisYear=    " + myUsageStats.NumberParsingsThisYear);


                    //----------------------------------------------------------------
                    // Show Version Information for Parser and Parser Interface
                    //----------------------------------------------------------------
                    log("");
                    log("VERSION INFORMATION");
                    log("GetParserVersionAsString()=   " + RecogniContact.GetParserVersionAsString());
                    log("GetInterfaceVersionAsString()=" + RecogniContact.GetInterfaceVersionAsString());
                    log("");


                    //----------------------------------------------------------------
                    // Parse Text and Show Result
                    //----------------------------------------------------------------

                    //NOTE!
                    //  parse() tries to interpret the entire text as an address/contact data string.
                    //To SEARCH a text - such as CVs, resumes, web sites - for address and contact  
                    //information and parse it, use 
                    //  findAndParse() 

                    ParsingResult myParsingResult = RecogniContact.Parse(licenseKeyTextBox.Text, parseTextBox.Text);
                    //ParsingResult myParsingResult = RecogniContact.FindAndParse(licenseKeyTextBox.Text, parseTextBox.Text); 
                    

                    log("");
                    log("PARSING RESULT");

                    log("Prefix=         " + myParsingResult.Prefix);
                    log("FirstName=      " + myParsingResult.FirstName);
                    log("MiddleName=     " + myParsingResult.MiddleName);
                    log("LastName=       " + myParsingResult.LastName);
                    log("Suffix=         " + myParsingResult.Suffix);
                    log("Company=        " + myParsingResult.Company);
                    log("Company2=       " + myParsingResult.Company2);
                    log("Position=       " + myParsingResult.Position);
                    log("StreetAddress1= " + myParsingResult.StreetAddress1);
                    log("StreetAddress2= " + myParsingResult.StreetAddress2);
                    log("PostboxAddress= " + myParsingResult.PostboxAddress);
                    log("PostboxPostCode=" + myParsingResult.PostboxPostCode);
                    log("PostCode=       " + myParsingResult.PostCode);
                    log("PlaceName=      " + myParsingResult.PlaceName);
                    log("Province=       " + myParsingResult.Province);
                    log("Country=        " + myParsingResult.Country);
                    log("Phone1=         " + myParsingResult.Phone1);
                    log("Phone2=         " + myParsingResult.Phone2);
                    log("Mobile=         " + myParsingResult.Mobile);
                    log("Fax=            " + myParsingResult.Fax);
                    log("Email=          " + myParsingResult.Email);
                    log("Url=            " + myParsingResult.Url);
                    log("Gender=         " + myParsingResult.Gender);
                    log("CountryIsoCode= " + myParsingResult.CountryIsoCode);

                    log("");


                    //handle unrecognized items
                    string[] UnrecognizedItemsArray = myParsingResult.UnrecognizedItems.Split('|');
                    log("Number unrecognized items: " + UnrecognizedItemsArray.Length);
                    foreach (string item in UnrecognizedItemsArray)
                    {
                        log("Unrecognized item: " + item);
                    }

                }
                catch (SystemException myException)
                {
                    log(myException.Message);

                   

                    string errorcodeid = "RecogniContact Error ";

                    if (myException.Message.StartsWith(errorcodeid))
                    {

                        string errorcodestring = myException.Message.Substring(errorcodeid.Length, 2).TrimEnd(':');

                        int errorcode = Convert.ToInt32(errorcodestring);

                        switch (errorcode)
                        {

                            case 1: //Invalid license key
                                //-----------------------------
                                //The license key provided is invalid
                                log("errorcode = " + Convert.ToString(errorcode));
                                break;

                            case 2: //Invalid request IP
                                //-----------------------------
                                //The license does not allow web service requests from the current IP address
                                log("errorcode = " + Convert.ToString(errorcode));
                                break;

                            case 10://License has expired
                                //-----------------------------
                                //A time limit was set for your license and this limit was reached

                                log("errorcode = " + Convert.ToString(errorcode));
                                break;

                            case 20://Parsing quota exceeded
                                //-----------------------------
                                //A maximum number of permitted parsing operations is set for your license 
                                //and this limit was exceeded. 

                                //The quota can be set per day/week/month/quarter/year or as a total limit
                                log("errorcode = " + Convert.ToString(errorcode));
                                break;

                            case 30://Unlicensed country
                                //-----------------------------
                                //The country of the specified address or contact data is 
                                //not included in your license 
                                log("errorcode = " + Convert.ToString(errorcode));
                                break;

                            case 99://Internal RecogniContact server error
                                //------------------------------------
                                //An unexprected error occured on the RecogniContact server.
                                //Please contact LoquiSoft for assistance.
                                log("errorcode = " + Convert.ToString(errorcode));
                                break;


                            case 0: //Other error
                                //-----------------------------
                                //Exception was not created by RecogniContact
                                break;
                        }
                    }
                }
            

            //scroll to end of outputTextBox
            outputTextBox.SelectionStart = outputTextBox.Text.Length;
            outputTextBox.ScrollToCaret();
        }
    }
}