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

Onlinenic API in C# (Part 1)

Onlinenic API with C#

Some weeks ago I had to build a complete library to work with Onlinenic’s API. After spending about a week on this awful API I managed to develop one.

A technical independent pdf document was released by Onlinenic but it is not clear; however I attached this file to this post. The first is from Onlinenic, the other is from an unknown source.

Because unfortunately I couldn’t find any technical document on the web in any platforms, I decided to write a post about this issue in c#. I hope you find it useful. This article contains: establishing connection, login to API and log out from API. You can read the rest in another postOnlinenic API in C# (Part 2).

Connecting to API:

Firstly, you should know that it only accepts TCP connection. So you should build a TCP connection to connect to this API.

You should send your command in an XML format, AIP also sends its response in this format too.

In order to connect to the API you can use this method:

bool Connect()

{

client = new TcpClient();

// Server name is <a href="http://www.onlinenic.com/">www.onlinenic.com</a> and port no is 30009

client.Connect(ServerName, PortNo);

stream = client.GetStream();

// String to store the response ASCII representation.

String responseData = String.Empty;

// Buffer to store the response bytes.

Byte[] data = new Byte[256];

// Read the first batch of the TcpServer response bytes.

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

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

bool flag = responseData.Contains("Your Connection with API Server is Successful");

if (!flag)

throw new NotConnectedException();

return flag;

}

You can catch response in two ways:

1- Response code: <code>1000</code>, an example for successful attempt

2- Response message :<msg>Server response</msg>

I used msg tag to make my program more readable.

I also wrote some exception classes to response to errors properly. As you can see “NotConnectedException” class is created to throw an exception in the case of connection failure.

Login:

In order to login to API you should specify your credential information. In code below you can make an XML command and pass it to the server.

There is a hashed value called checksum which exists in all of commands either you send to API or receive from it. This is for security purposes to prevent anyone from intersecting the connection and changing the value of the fields. Each command such as login or Domain registration has its own checksum format. Here as you cans see below it is the concatenation of username, hashed password, a new GUID and a string contains “login”. You then should hash it.

To hash your password you can click on this.

bool Login()

{

string chksum = "";

string HashedPass = getMd5Hash(Password);

Guid guid = Guid.NewGuid();

// MemberID is your username and for you password you should hash you password

chksum = MemberID + HashedPass + guid.ToString() + "login";

chksum = getMd5Hash(chksum);

StringBuilder sb = new StringBuilder();

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

sb.Append("<request>");

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

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

sb.Append("<params>");

sb.Append("<param name=\"clid\">" + MemberID + "</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)

throw new NotLoginException();

return flag;

}

Log out:

bool Logout()

{

string chksum = "";

string HashedPass = getMd5Hash(Password);

Guid guid = Guid.NewGuid();

chksum = MemberID + HashedPass + guid.ToString() + "logout";

chksum = getMd5Hash(chksum);

StringBuilder sb = new StringBuilder();

sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
sb.Append("<request>");
sb.Append("<category>client</category>");
sb.Append("<action>Logout</action>");
sb.Append("<params>");
sb.Append("<param name=\"clid\">" + MemberID + "</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");

return flag;

}
Advertisements
  1. May 17, 2011 at 12:09 pm

    hi i need help:
    i use this article
    but my app doesnt working
    can u help me
    i dont understand where is FALSE
    this .cs http://www.destekyeri.com/CS.htm
    our port open
    i wait your answer please

  2. May 17, 2011 at 12:26 pm

    Akif AKINCI :
    hi i need help:
    i use this article
    but my app doesnt working
    can u help me
    i dont understand where is FALSE
    this .cs http://www.destekyeri.com/CS.htm
    our port open
    i wait your answer please

    our error http://www.sanalog.com/baglanVeLoginOl.aspx

    • May 17, 2011 at 2:36 pm

      Hi, what do you receive as the response from Onlinenic API? Can you make a screen shot from your code, since some portion of code is changed to html code. 😉

  3. May 17, 2011 at 8:18 pm

    Akif AKINCI :

    M.H.Sarshar :
    Hi, what do you receive as the response from Onlinenic API? Can you make a screen shot from your code, since some portion of code is changed to html code.

    same screen http://www.destekyeri.com/CS.htm code is here

    Yes, I got you problem, there is a problem with WordPress, It changes html tags to different one e.g. ‘<' to '&lt'. I emailed them to change it still sucks. I should change it asap from text to image.
    Thanks for your comment

  4. May 18, 2011 at 7:19 am

    hi can you give me your login application. i am change online my id & password.
    so only connect and login – i use (VisualStudio 2010)
    did u see my code http://www.destekyeri.com/CS.htm tgis is my onlinenic.aspx.cs file

    onlinenic.aspx file

    response – connect / no connect and login/no login
    our code download link http://www.sanalog.com/onlinenic.rar

  5. May 18, 2011 at 8:03 am

    I try to connect and login with the codes below. I can connect but my login code doesn’t work. I can’t login. My codes are below.
    what’s my problem. i need help 🙂

    • May 18, 2011 at 4:14 pm

      you can check the new version now, please refer again to the post and copy the new code, word press have changed some tags of my post while changing my theme,
      Thanks you informed me buddy 😉

  6. May 18, 2011 at 6:45 pm

    thanks for help, Now working

  7. November 23, 2011 at 1:19 pm

    offf. i need to modify dns code in c#.
    help me please.

    login, logout is working but i don’t run modfy domain or dns

    exm: string HashedPass = CreateMd5Hash(testPassword);
    Guid guid = Guid.NewGuid();
    string chksum = CreateMd5Hash(testID + HashedPass + clTRID + “upddomain” + “0” + domainName + domaindns1 + domaindns2 + AuthInfo);
    StringBuilder sb = new StringBuilder();
    sb.Append(“”);
    sb.Append(“”);
    sb.Append(“”);
    sb.Append(” “);
    sb.Append(“”);
    sb.Append(“domain-1.0.xsd>”);
    sb.Append(“0”);
    sb.Append(“y-z-c.com”);
    sb.Append(“”);
    sb.Append(“ns4.onlinenic.com”);
    sb.Append(“ns1.onlinenic.com”);
    sb.Append(“”);
    sb.Append(“”);
    sb.Append(“”);
    sb.Append(“”);
    sb.Append(“UPDD-0019”);
    sb.Append(“” + chksum + “”);
    sb.Append(“”);
    sb.Append(“”);

    String responseData = String.Empty;
    Byte[] data;
    data = System.Text.Encoding.ASCII.GetBytes(sb.ToString());
    stream.Write(data, 0, data.Length);
    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);

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: