Express Entry:Global CSharp

From Melissa Data Wiki
Jump to: navigation, search

← Express Entry Reference

Express Entry Navigation
Introduction
Getting Started
Global Getting Started
Global Terms
Endpoints
ExpressAddress
ExpressCityState
ExpressFreeForm
ExpressPostalCode
ExpressStreet
GlobalExpressAddress
GlobalExpressCountry
GlobalExpressLocalityAdministrativeArea
GlobalExpressFreeForm
GlobalExpressPostalCode
GlobalExpressThoroughfare
Response
XML Response
JSON Response
Global XML Response
Global JSON Response
Token Server
Result Codes
Express Entry Result Codes
Sample Code
US CSharp
US JavaScript
US Visual BASIC
Global CSharp
Global JavaScript
Token Server Support



Global REST CSharp2008 Sample Project


Global REST CSharp2008 Sample 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 System.Web;
using System.Net;
using System.Xml;
using System.Xml.Serialization;

namespace GlobalExpressFreeForm
{
    public partial class Form1 : Form
    {
        bool isInitialized = false;     //set to false until the application is initialized
        HttpWebRequest request;         //
        HttpWebResponse response;
        System.IO.Stream responseReader;
        Uri address;
        String tServer;
        XmlDocument xmlDoc;
        System.Xml.XmlDocument rootNode = new System.Xml.XmlDocument();
        String[] Tempstr = new String[7];



        public Form1()
        {
            InitializeComponent();
        }

        private void ListView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            if (ListView1.SelectedItems.Count > 0)
            {
                //Clear the combo box before populating
            
                TxtZIP.Text = ListView1.SelectedItems[0].SubItems[3].Text;
                TxtState.Text = ListView1.SelectedItems[0].SubItems[2].Text;
                TxtCity.Text = ListView1.SelectedItems[0].SubItems[1].Text;
                TextAddress.Text = ListView1.SelectedItems[0].SubItems[0].Text;
                                                               
            }
        }
        private void TextAddress_KeyUp(object sender, KeyEventArgs e)
        {
            if (isInitialized == false)
            {
                //Set up column labels and initialize
                //ListView1.Columns.Add("Country", 40);
                ListView1.Columns.Add("Address", 300);
                ListView1.Columns.Add("Locality", 100);
                ListView1.Columns.Add("Admin. Area", 100);
                ListView1.Columns.Add("Postal Code", 100);

                //ListView1.Columns.Add("Suite Name", 90);  commented out 2/21/14
                //ListView1.Columns.Add("Suite Range", 100);
                ListView1.FullRowSelect = true;
                ListView1.ShowItemToolTips = true;
                ListView1.View = View.Details;

                isInitialized = true;
            }
            else
            {
                ListView1.Items.Clear(); //clear the listview
                txtResults.Clear();

                tServer = "http://expressentry.melissadata.net/web/GlobalExpressFreeForm"; //The server where the Express Entry service is located,
                                                                                                // with full URL

                //use escape codes with License Keys, or the server will not respond to pluses and other symbols
                String auth;
                auth = Uri.EscapeDataString(TxtCustID.Text);
                tServer += "?id=" + auth;

                tServer += "&ff=" + TextAddress.Text;
                tServer += "&maxrecords=" + txtMaxMatches.Text;
                tServer += "&Country=" + CountryBox.Text;
                tServer += "&format=XML";
                

                address = new Uri(tServer);

                // Create the web request
                request = (HttpWebRequest)WebRequest.Create(address);

                // Get response   
                response = (HttpWebResponse)request.GetResponse();

                // Get the response stream into a reader
                responseReader = response.GetResponseStream();

                XmlTextWriter outXML = new XmlTextWriter("response.xml", null);

                xmlDoc = new XmlDocument();
                xmlDoc.Load(responseReader);
                xmlDoc.Save(outXML);
                outXML.Close();

                // Load root node of the XML Response
                rootNode.Load("response.xml");

                PopulateNodes(rootNode);

                response.Close();
                responseReader.Close();

            }
        }
    /***************************************************************************
    / Functions to Populate The Output Fields
    ****************************************************************************/
    // Populate Output Fields that have existing nodes
    public void Add(XmlNode theNode ) 
    {
        
        //else
        if (theNode.ParentNode.Name == "Address1") 
            Tempstr[0] = theNode.Value;
        else if (theNode.ParentNode.Name == "Locality") 
            Tempstr[1] = theNode.Value;
        else if (theNode.ParentNode.Name == "AdministrativeArea")
            Tempstr[2] = theNode.Value;
        else if (theNode.ParentNode.Name == "PostalCode")
        {
            Tempstr[3] = theNode.Value;
            ListViewItem itm = new ListViewItem(Tempstr);
            ListView1.Items.Add(itm);
        }
        
    }


    public void PopulateNodes(XmlDocument xml)
    {
        foreach (XmlNode xmlnode in xml)
        {
            SearchRecord(xmlnode);
        }
    }

    public void SearchRecord(XmlNode xml)
    {
        
        foreach (XmlNode xmlNode in xml)
        {
            if (xmlNode.Name == "ResultCode" & xmlNode.HasChildNodes)
            {
                String errorCodeString = xmlNode.InnerText;
                String[] errorCodeList = errorCodeString.Split( ',' );
                
                foreach (String errorCode in errorCodeList)
                {
                    switch (errorCode)
                    {
                        case "SE01":
                            txtResults.Text += errorCode + ": Authorization check failed;  ";
                            break;
                        case "GE01":
                            txtResults.Text += errorCode + ": Empty XML Request Structure;  ";
                            break;
                        case "GE02":
                            txtResults.Text += errorCode + ": Empty XML Request Record Structure;  ";
                            break;
                        case "GE03":
                            txtResults.Text += errorCode + ": Counted records send more than number of records allowed per request;  ";
                            break;
                        case "GE04":
                            txtResults.Text += errorCode + ": License Key empty;  ";
                            break;
                        case "GE05":
                            txtResults.Text += errorCode + ": License Key not valid;  ";
                            break;
                        case "GE06":
                            txtResults.Text += errorCode + ": License Key disabled;  ";
                            break;
                        case "GE07":
                            txtResults.Text += errorCode + ": XML Request invalid;  ";
                            break;
                        case "CS00":
                            txtResults.Text = errorCode + ": Search returned at least one result;  ";
                            break;
                        case "GE08":
                            txtResults.Text += errorCode + ": License Key is not valid for this product;  ";
                            break;
                        case "CE00":
                            txtResults.Text += errorCode + ": Search completed, no results found;  ";
                            break;
                        case "CE01":
                            txtResults.Text += errorCode + ": Search failed because of a bad setup (mdHints UE01);  ";
                            break;
                        case "CE02":
                            txtResults.Text += errorCode + ": Search failed because of a search error (mdHints UE02);  ";
                            break;
                        case "XS01":
                            txtResults.Text += errorCode + ": Complete Result Set Returned";
                            break;
                        case "XS02":
                            txtResults.Text += errorCode + ": Partial set of results returned";
                            break;
                        case "XS03":
                            txtResults.Text += errorCode + ": Search completed - no results found";
                            break;

                    }
                }
            }
            else if (xmlNode.Name == "Results" & xmlNode.HasChildNodes)
            {
                PopulateSubNodes(xmlNode);
            }
        }
    }

    private void PopulateSubNodes(XmlNode parentxmlnode)
    {
        foreach (XmlNode node in parentxmlnode)
        {
            Add(node);
            PopulateSubNodes(node);
        }
    }

        private void txtResults_TextChanged(object sender, EventArgs e)
        {
        
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label11_Click( object sender, EventArgs e)
        {

        }

        private void lblCompleteZIP_Click(object sender, EventArgs e)
        {

        }

        private void TxtCustID_TextChanged(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {

        }

        private void TextAddress_TextChanged(object sender, EventArgs e)
        {

        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            TextAddress.Clear();
            TxtCity.Clear();
            TxtState.Clear();
            TxtZIP.Clear();
            ListView1.Clear();
            txtResults.Clear();
        }
    }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Products
Support