Express Entry: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



US REST CSharp2008 Sample Project


US 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 ExpressFreeForm
{
  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)
      {
                
        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("Address", 140);
        ListView1.Columns.Add("City", 100);
        ListView1.Columns.Add("State", 50);
        ListView1.Columns.Add("Zip Code", 100);

        ListView1.Columns.Add("Suite Name", 90);
        //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/ExpressFreeForm"; //The server where Express Entry is located.

        //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 += "&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 ) 
  {
    
    if (theNode.ParentNode.Name == "AddressLine1") 
      Tempstr[0] = theNode.Value;
    else if (theNode.ParentNode.Name == "City") 
      Tempstr[1] = theNode.Value;
    else if (theNode.ParentNode.Name == "State")
      Tempstr[2] = theNode.Value;
    else if (theNode.ParentNode.Name == "PostalCode")
    {
      Tempstr[3] = theNode.Value;
      
    }
    else if (theNode.ParentNode.Name == "SuiteName" /* && theNode.Value != "Usaid" */)
    {
      //Save the Suite Name
      Tempstr[4] = theNode.Value;
    }
    else if (theNode.ParentNode.Name == "SuiteRange")
    {  //Save the Suite Range
      //Tempstr[5] = theNode.Value;
    }
    else if (theNode.ParentNode.Name == "SuiteCount")
    {
      if ( theNode.Value.Equals( "0" ) )
        Tempstr[6] = "No";
      else Tempstr[6] = "Yes";
      //Upon receiving SuiteCount, populate the ListView
      ListViewItem itm = null;
      itm = new ListViewItem(Tempstr);
      ListView1.Items.Add(itm);
      //Clear Suite information for those that have none
      Tempstr[4] = "";
      Tempstr[5] = "";
      Tempstr[6] = "";
    }
  }


  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 button1_Click(object sender, EventArgs e)
    {
      TextAddress.Clear();
      TxtCity.Clear();
      TxtState.Clear();
      TxtZIP.Clear();
      ListView1.Clear();
      isInitialized = false;
      TextAddress.Focus();
    }
  }
}
Personal tools
Namespaces

Variants
Actions
Navigation
Products
Support