Web service integration using C
From KnowledgeTree Document Management Made Simple
You made a wise choice in C# as the unit tests were written in for Mono via C#. Check C:\ktdms\knowledgeTree\ktwebservice\nunit (or wherever you have kt installed). You will find the whole gamut in C#. Joy!
Authentication
Here's an example of a console application that authenticates using KnowledgeTreePortClient.login()
using System;
using System.Text;
using KTlab.KnowledgeTreeServiceReference; //make sure you add this service reference
namespace KTlab
{
class Program
{
static void Main(string[] args)
{
string strUserName = "admin";
string strPassword = "admin";
string strIP = "127.0.0.1";
KnowledgeTreePortClient objWebservice = new KnowledgeTreePortClient();
kt_response objResponse;
Console.WriteLine("Attempting to connect...");
objResponse = objWebservice.login(strUserName, strPassword, strIP);
if (objResponse.status_code != 0)
{
Console.WriteLine("Cannot authenticate. Reason: " + objResponse.message);
}
else
{
//put code here
}
Console.WriteLine("Logging out...");
objWebservice.logout(strSession);
Console.WriteLine("Goodbye.");
}
// debug pause
Console.WriteLine("Press Enter to exit");
Console.ReadLine();
}
}
}
Here is another example using ASP.NET C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ktWebservice;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strUsername = "admin";
string strPassword = "admin";
string strIpAddress = "127.0.0.1";
//instantiate a KT response object..
kt_response objKTResponse = new kt_response();
//instantiate the KT webservice Proxy..
KnowledgeTreeService objKTService = new ktWebservice.KnowledgeTreeService();
//Call the Login Method on the proxy object.
objKTResponse = objKTService.login(strUsername,strPassword,strIpAddress);
Response.Write("Status Code : "+objKTResponse.status_code.ToString()+"<p/>");
//Authentication Validation
if (objKTResponse.status_code == 0)
{
Response.Write("Login Sucessfull");
Response.Write("<p>Session Id: "+objKTResponse.message+"<p/>");
//instantiate the folder contents object that will hold a reference to the folder contents
kt_folder_contents objKTFolderContents = new kt_folder_contents();
//instantiate the folder collection
kt_folder_item[] kt_folder_collection;
//browse the root folder contents, 1 = root folder.
objKTFolderContents = objKTService.get_folder_contents(objKTResponse.message,4, 1, "D");
Response.Write("Folder Name: "+objKTFolderContents.folder_name+"<p/>");
Response.Write("Folder Id: " + objKTFolderContents.folder_id+ "<p/>");
Response.Write("Full Path: " + objKTFolderContents.full_path + "<p/>");
//assign the items collection to the folder collection object
Response.Write("Status Code: " + objKTFolderContents.status_code.ToString() + "<p/>");
//iterate and display the folder contents...
Response.Write("Folder Contents<p/>================================<p/>");
kt_folder_collection = objKTFolderContents.items;
foreach (kt_folder_item objItems in kt_folder_collection)
{
Response.Write(objItems.filename+"<p/>");
}
}
else
{
Response.Write("Error Authenticating, Please provide a valid username or password <p/>"+objKTResponse.message);
}
}
}
del.icio.us
reddit

