Home > APIs > Onlinenic API in C# (Part 2)

Onlinenic API in C# (Part 2)

In this article we will discuss about some functionalities of Onlinenic API. We should know that for each function we can establish a new connection. (A good practice is placing connect and login method in the constructor of a class).

Onlinenic API with C#

This article will cover domain availability checking, retrieving domain information and creation of domain. I tried to make you familiar to code the rest yourself, should you encountered any question you can email or comment me.

Domain availability checking:

This function is one of the simplest function in this API. You just need to send your domain name and the extension code of your desired domain. For example “google.com” as domain name and “0” for extension which is “.com”.

/// <summary>
/// Checks the availability of domain name

/// </summary>

/// <param name="domainName">Name of domain e.g. yahoo.com</param>

/// <param name="domainExt">Extension number of domain e.g. 800 for biz</param>

/// <returns>true means domain is available and false means domain is not available</returns>

public bool CheckDomain(string domainName, string domainExt)

{

string chksum = "";

string HashedPass = getMd5Hash(Password);

Guid guid = Guid.NewGuid();

chksum = MemberID + HashedPass + guid.ToString() + "checkdomain" + domainExt + domainName;

chksum = getMd5Hash(chksum);

StringBuilder sb = new StringBuilder();

sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");

sb.Append("<request>");

sb.Append("<category>domain</category>");

sb.Append("<action>CheckDomain</action>");

sb.Append("<params>");

//Domain extension should be the code of a domain name. For example 0 for .com

sb.Append("     <param name=\"domaintype\">" + domainExt.ToString() + "</param>");

//Domain name should be the complete form of a domain name. For example microsoft.com

sb.Append("     <param name=\"domain\">" + domainName + "</param>");

sb.Append("</params>");

sb.Append("<cltrid>" + guid.ToString() + "</cltrid>");

sb.Append("<chksum>" + chksum + "</chksum>");

sb.Append("</request>");
String responseData = String.Empty;

// Buffer to store the response bytes.

Byte[] data;

data = System.Text.Encoding.ASCII.GetBytes(sb.ToString());

// Send the message to the connected TcpServer.

stream.Write(data, 0, data.Length);

//Reads data and returns it to the application

Int32 bytes = stream.Read(data, 0, data.Length);

responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

if (!responseData.Contains("Command completed successfully"))

{

return false;

}

return responseData.Contains("&lt;data name=\"avail\"&gt;1&lt;/data&gt;");

}

Retrieving domain information:

This section is really important because finding the real meaning of this command wasted a lot of my time just to debug and search about this job. Onlinenic API does not retrieve information of all domains; it only does it for domains which are registered under your account. So don’t waste your time to get this functionality.

/// <summary>;

/// Returns the information about a registered domain under your account

/// </summary>

/// <param name="domainName">Name of domain e.g. yahoo.com</param>

/// <param name="domainExt">Extension number of domain e.g. 800 for biz</param>

/// <returns>An xml-based string response</returns>

public string getDomainInfo(string domainName, string domainExt)

{

string chksum = "";

string HashedPass = getMd5Hash(Password);

Guid guid = Guid.NewGuid();

chksum = MemberID + HashedPass + guid.ToString() + "infodomain" +

domainExt + domainName;

chksum = getMd5Hash(chksum);

StringBuilder sb = new StringBuilder();

sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");

sb.Append("<request>");

sb.Append("<category>domain</category>");

sb.Append("<action>InfoDomain</action>");

sb.Append("<params>");

sb.Append("     <param name=\"domaintype\">" + domainExt + "</param>");

sb.Append("     <param name=\"domain\">" + domainName + "</param>");

sb.Append("</params>");

sb.Append("<cltrid>" + guid.ToString() + "</cltrid>");

sb.Append("<chksum>" + chksum + "</chksum>");

sb.Append("</request>");
String responseData = String.Empty;

Byte[] data;

data = System.Text.Encoding.ASCII.GetBytes(sb.ToString());

// Send the message to the connected TcpServer.

stream.Write(data, 0, data.Length);

//Reads data and returns it to the application

Int32 bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

byte[] byteArray = Encoding.ASCII.GetBytes(responseData);

MemoryStream memStream = new MemoryStream(byteArray);

if (!responseData.Contains("Command completed successfully"))

{

return "";

}

else

{

responseData = ParseXMLstream(memStream);

}

return responseData;

}

Domain Creation:

This topic also was one of the most challenging sections of my job because comments in the published documents are totally unclear.

Creation of domain contact:

In order to create/register a domain you should create/register an entity called contact. This entity contains information about persons in charged with this domain, their contact information and some other. It is important to know that creation of contact for each domain extension has a common part and a specific part which differs from one domain extension to another. You should know that for .EU and .Asia domain extensions you should specify country codes related to these regions [you can refer to the document for detailed information].

I tried to build it clearly and use comments to help you learn it easier.

/// <summary>

/// Creates contact which is required for domain registration

/// </summary>

/// <param name="domainExt">Extension number of domain e.g. 800 for biz</param>

/// <param name="name">Name of contact person</param>

/// <param name="organization">Organization of contact person</param>

/// <param name="country">Country of contact person. It is a string with length of 2 e.g. IR for Iran. You should consider domain extension for correct country, for example IR cannot be used as the country of a .EU domain extension</param>

/// <param name="province">Province of contact person</param>

/// <param name="city">City of contact person</param>

/// <param name="street">Address of contact person</param>

/// <param name="postCode">Post code of contact person</param>

/// <param name="phoneNo">Pnone no of contact person</param>

/// <param name="faxNo">Fax number of contact person</param>

/// <param name="email">Email address of contact person</param>

/// <param name="password">Password of contact object</param>

/// <returns>A string of created contact</returns>

public string CreateContact(string domainExt, string name, string organization, string country, string province, string city, string street, string postCode,

string phoneNo, string faxNo, string email, string password)

{

string chksum = "";

string HashedPass = getMd5Hash(Password);

Guid guid = Guid.NewGuid();

chksum = MemberID + HashedPass + guid.ToString() + "crtcontact" + name + organization + email;

chksum = getMd5Hash(chksum);

StringBuilder sb = new StringBuilder();

sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");

sb.Append("<request>");

sb.Append("<category>domain</category>");

sb.Append("<action>CreateContact</action>");

sb.Append("<params>");

sb.Append("<param name=\"domaintype\">" + domainExt + "</param>");

sb.Append("<param name=\"name\">" + name + "</param>");

sb.Append("<param name=\"org\">" + organization + "</param>");

sb.Append("<param name=\"country\">" + country + "</param>");

sb.Append("<param name=\"province\">" + province + "</param>");

sb.Append("<param name=\"city\">" + city + "</param>");

sb.Append("<param name=\"street\">" + stream + "</param>");

sb.Append("<param name=\"postalcode\">" + postCode + "</param>");

sb.Append("<param name=\"voice\">" + phoneNo + "</param>");

sb.Append("<param name=\"fax\">" + faxNo + "</param>");

sb.Append("<param name=\"email\">" + email + "</param>");

sb.Append("<param name=\"password\">" + password + "</param>");

switch (domainExt)

{

case "902": // .EU

sb.Append("<param name=\"euflag\">" + "1" + "</param>");

sb.Append("<param name=\"regtype\">" + "In" + "</param>");

break;

case "220": // .CN

sb.Append("<param name=\"manager\">" + "Your Name" + "</param>");

sb.Append("<param name=\"industry\">" + "S2" + "</param>");

break;

case "905": // .ASIA

sb.Append("<param name=\"ccLocality\">" + "IR" + "</param>");

sb.Append("<param name=\"localitySp\">" + "Tehran" + "</param>");

sb.Append("<param name=\"localityCity\">" + "Tehran" + "</param>");

sb.Append("<param name=\"legalEntityType\">" + "corporation" + "</param>");

sb.Append("<param name=\"identForm\">" + "other" + "</param>");

sb.Append("<param name=\"identNumber\">" + "122211122" + "</param>");

sb.Append("<param name=\"otherIdentForm\">" + "other" + "</param>");

break;

case "806": // .US

sb.Append("<param name=\"AppPurpose\">" + "P1" + "</param>");

sb.Append("<param name=\"NexusCategory\">" + "C12" + "</param>");

break;

}

sb.Append("</params>");

sb.Append("<cltrid>" + guid.ToString() + "</cltrid>");

sb.Append("<chksum>" + chksum + "</chksum>");

sb.Append("</request>");

String responseData = String.Empty;

// Buffer to store the response bytes.

Byte[] data;

data = System.Text.Encoding.ASCII.GetBytes(sb.ToString());

// Send the message to the connected TcpServer.

stream.Write(data, 0, data.Length);

//Reads data and returns it to the application

Int32 bytes = stream.Read(data, 0, data.Length);

responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

byte[] byteArray = Encoding.ASCII.GetBytes(responseData);

MemoryStream memStream = new MemoryStream(byteArray);

if (responseData.Contains("Command completed successfully"))

{

responseData = ParseXMLstream(memStream, "data");

}

return responseData;

}

Registration of a domain:

After creation of one or more contact objects it is feasible to register a domain. You should create at least one contact object for each domain registration. Also you should specify name servers of each domain. You should mention that for registration of different domain extensions, different checksum order should be specified.

/// <summary>

/// Registered an availabe domain under your account. You should build at least one contact before registration of a domain

/// </summary>

/// <param name="domainName">Name of domain e.g. yahoo.com</param>

/// <param name="domainExt">Extension number of domain e.g. 800 for biz</param>

/// <param name="period">The amount of domain registration. e.g. 2 for 2 years</param>

/// <param name="NS1">Name server number 1</param>

/// <param name="NS2">Name server number 2</param>

/// <param name="password">Password of domain object</param>

/// <param name="contact">The created contact of </param>

/// <returns>Returns true if domain is successfully registerd</returns>

public bool createDomain(string domainName, string domainExt, string period,

string NS1, string NS2, string password, string contact)

{

string chksum = "";

string HashedPass = getMd5Hash(Password);

Guid guid = Guid.NewGuid();

switch (domainExt)

{

case "902": //.EU

chksum = MemberID + HashedPass + guid.ToString() + "createdomain" + domainExt + domainName + period + NS1 + NS2 + contact + password;

break;

case "905"://.ASIA

chksum = MemberID + HashedPass + guid.ToString() + "createdomain" + domainExt + domainName +

period + NS1 + NS2 + contact + contact + contact + contact + contact + password;

break;

default:

chksum = MemberID + HashedPass + guid.ToString() + "createdomain" + domainExt + domainName + period + NS1 + NS2 + contact + contact + contact + contact + password;

break;

}

chksum = getMd5Hash(chksum);

StringBuilder sb = new StringBuilder();

sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");

sb.Append("<request>");

sb.Append("<category>domain</category>");

sb.Append("<action>CreateDomain</action>");

sb.Append("<params>");

sb.Append("     <param name=\"domaintype\">" + domainExt + "</param>");

sb.Append("     <param name=\"domain\">" + domainName + "</param>");

sb.Append("     <param name=\"mltype\">" + "0" + "</param>");

sb.Append("     <param name=\"period\">" + period + "</param>");

sb.Append("     <param name=\"dns\">" + NS1 + "</param>");

sb.Append("     <param name=\"dns\">" + NS2 + "</param>");

sb.Append("     <param name=\"registrant\">" + contact + "</param>");

sb.Append("     <param name=\"tech\">" + contact + "</param>");

sb.Append("     <param name=\"billing\">" + contact + "</param>");

sb.Append("     <param name=\"admin\">" + contact + "</param>");

sb.Append("     <param name=\"password\">" + password + "</param>");

sb.Append("</params>");

sb.Append("<cltrid>" + guid.ToString() + "</cltrid>");

sb.Append("<chksum>" + chksum + "</chksum>");

sb.Append("</request>");
String responseData = String.Empty;

// Buffer to store the response bytes.

Byte[] data;

data = System.Text.Encoding.ASCII.GetBytes(sb.ToString());

//Send the message to the connected TcpServer.

stream.Write(data, 0, data.Length);

//Reads data and returns it to the application

Int32 bytes = stream.Read(data, 0, data.Length);

responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bytes = stream.Read(data, 0, data.Length);

responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

bool flag = responseData.Contains("Command completed successfully");

if (!flag)

{

return false;

}

return flag;

}

I wish you found it useful.

  1. Anonymous
    May 27, 2011 at 6:34 pm

    hi.
    I try your codes.
    but I can not work this codes.
    what is problem.
    can you help me.
    you can download my code here
    http://hotfile.com/dl/119094169/885467c/mycodes.rar.html

    • May 27, 2011 at 7:23 pm

      Hi there,
      would you describe a bit about the section you want to use, did you use code samples in the 1st part of this article? was it successful?

  2. tolga
    May 27, 2011 at 8:45 pm

    hi.
    thanks for answer.
    connect method is working
    login method is working.
    create contact method is working.
    but domainregister method is not working.
    return responsedata empty.
    why?
    have you idea.

    • May 28, 2011 at 4:48 pm

      Your welcome, I’ll read your code sample uploaded and answer you in 2 days, and would you write some type of testimonials under the 1st part of this article if it works for you.

      Thanks 😉

  3. tolga
    May 29, 2011 at 8:13 am

    thanks for interest.
    I am waiting your answer.

  4. June 1, 2011 at 3:27 pm

    Hi tolga;
    I checked your code, first of all, which domain extension do you want to register?
    secondly, If it is .com, I repeated a section of code about 10 times:

    responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    byte[] byteArray = Encoding.ASCII.GetBytes(responseData);

    but you didn’t do this. I think “Command completed successfully” is not catches yet when you return the response with this number of iteration. Unfortunately, a for loop can’t work here.

    Please check these items.

  5. tolga
    June 2, 2011 at 10:18 am

    thanks for your answer.
    I’m trying to get .org. but now I’ve tried to get .com. While I’m trying to get .com and .org there occured some diffirent error.
    While I’m trying to get .com, it occured “root element is missing” at the 192. line.

    182 Int32 bytes = stream.Read(data, 0, data.Length);
    183 responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    184 bytes = stream.Read(data, 0, data.Length);
    185 responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    186 bytes = stream.Read(data, 0, data.Length);
    187 responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    188 bytes = stream.Read(data, 0, data.Length);
    189 responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    190 bytes = stream.Read(data, 0, data.Length);
    191 responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    192 bytes = stream.Read(data, 0, data.Length);
    responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    bytes = stream.Read(data, 0, data.Length);
    responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    bytes = stream.Read(data, 0, data.Length);
    responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    bytes = stream.Read(data, 0, data.Length);
    responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);
    bytes = stream.Read(data, 0, data.Length);
    responseData += System.Text.Encoding.ASCII.GetString(data, 0, bytes);

    but While I’m trying to get .org , I don’t get my error. Tehre is no difference if I write 1 or 10 times there lines above. The respond that I’m getting is always empty. I’ve written this onlinenic.com but they didn’t give me my help. I’ll be glad if you help me.

    • June 5, 2011 at 3:01 pm

      Dear tolga, after reading your code I saw some coding mistakes.
      first of all your checksum is not in a correct order, yours is “domainName + domainExt” while it must be opposite (please take a look at my article again), the next one is the password that is not the test password. You used a variable called “safir”. There may be more mistakes, please check them carefully.

  6. arezoo
    July 29, 2011 at 10:25 am

    hello
    thanks for Your article.
    i try create domain in your test server, but I get this error “Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.”
    i turn of my firewall and disable anti virus but i get this error yet.
    please help me

    • July 29, 2011 at 2:12 pm

      Hi Arezoo,

      Thanks ;),
      First of all, could you connect to the server which is described in the previous article?
      I mean this

      Since, if you couldn’t fulfill this section you can’t proceed to other functions.
      I’m grad to hear from you once again.

  7. November 23, 2011 at 2:00 pm

    i -so much- need to update dns code…
    oooof offf…

  1. No trackbacks yet.

Leave a reply to tolga Cancel reply