Thursday, September 16, 2010

Adding Alfresco web service from VS 2005

Alfresco is an open source Content Management System that allow user to store data inside the server. To make it simple it's just like a database where you can store data/file/image and add your desired property along with the data. Since most of alfresco client use java; actually alfresco is written in java so there are some challenge that .Net will face, including the scarcity of resource on the web. If you are a java user, you can include alfresco classes in your code, but for .Net user you should rewrite the code from .Net to Java which gonna waste your time, or you convert .class to .dll, I use IKVM to do the job, I'll cover that in the next post.

Coding environment
  1. Alfresco 3.3 Community edition
  2. Visual Studio .Net 2005
  3. Windows XP Pro version 2002 SP3

List of the web service in alfresco










Service NamePurposeURL
AccessControlServiceManage permissionshttp://host:port/alfresco/api/AccessControlService?WSDL
ActionServiceExecute custom actions and ruleshttp://host:port/alfresco/api/ActionService?WSDL
AdministrationServiceManage users and groupshttp://host:port/alfresco/api/AdministrationService?WSDL
AuthenticationServiceLogin and access session ticketshttp://host:port/alfresco/api/AuthenticationService?WSDL
AuthoringServiceAllows collaboration between usershttp://host:port/alfresco/api/AuthoringService?WSDL
ContentServiceRead and write contenthttp://host:port/alfresco/api/ContentService?WSDL
ClassificationServiceManage categorieshttp://host:port/alfresco/api/ClassificationService?WSDL
DictionaryServiceManage content modelshttp://host:port/alfresco/api/DictionaryService?WSDL
RepositoryServiceNavigate, search, and manipulate nodes.http://host:port/alfresco/api/RepositoryService?WSDL

I manage to add all the wsdl, but AccessControlService can not be call, I fail to update web reference also, maybe there are something wrong with it's schema.

Okay from here on, you need additional class to help you to communicate with the web service
  1. WebServiceFactory.cs
  2. AuthenticationUtils.cs
  3. Constants.cs
Thanks to this generous person who share his experience in communicating with alfresco, you can get this file http://forge.alfresco.com/frs/download.php/80/alfresco-dotNet-0.2Beta.zip.

You would likely encounter this error when you call WebServiceFactory.addSecurityHeader
"cannot convert from 'Alfresco.RepositoryWebService.RepositoryService' to 'Microsoft.Web.Services3.WebServicesClientProtocol'"

To fix this you must change file Reference.cs for every WSDL that you add in your code, example
  • public partial class ContentService : System.Web.Services.Protocols.SoapHttpClientProtocol
change into
  • public partial class ContentService : Microsoft.Web.Services3.WebServicesClientProtocol

It goes without saying you should add references Microsoft.Web.Services3

Still in WebServiceFactory don't forget to change this value and point it to your alfresco server
  • private const string DEFAULT_ENDPOINT_ADDRESS = "http://localhost:8080/alfresco"
That should do the job, in the next post I will cover insert document to alfresco.

Generate table from server side

I've been absent long enough :p, but few days ago, I found my post can be reference for myself so I decide to update again hohoho. For some reason I want to generate table(actually I don't know what reason, why didn't I used DataGrid or GridView instead of table)

I've make a generic function PopulateTable(Table tblObj, DataTable dtObject, TableRow trHeader), if needed you can edit according to your needs, because some data may need certain formatting in table. The code itself easy to understand

  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. //Assuming we have data in this tbl
  4. DataTable tbl = new DataTable();
  5. PopulateTable(tblContent, tbl, GetDocumentTableHeader());
  6. }
  7. private TableHeaderRow GetDocumentTableHeader()
  8. {
  9. TableHeaderRow thr = new TableHeaderRow();
  10. TableHeaderCell thc = new TableHeaderCell();
  11. thc.Text = "Title"; thc.CssClass = "title"; thr.Cells.Add(thc);
  12. thc = new TableHeaderCell();
  13. thc.Text = "Author"; thc.CssClass = "author"; thr.Cells.Add(thc);
  14. thc = new TableHeaderCell();
  15. thc.Text = "Description"; thc.CssClass = "categories"; thr.Cells.Add(thc);
  16. return thr;
  17. }
  18. private void PopulateTable(Table tblObj, DataTable dtObject, TableRow trHeader)
  19. {
  20. tblObj.Rows.Clear();
  21. tblObj.Rows.Add(trHeader);
  22. if (dtObject == null || dtObject.Rows.Count == 0)
  23. {
  24. //If no records found in DataTable then show No Result Found
  25. TableRow row = new TableRow();
  26. TableCell cell = new TableCell();
  27. cell.Text = "No Result Found!";
  28. cell.HorizontalAlign = HorizontalAlign.Center;
  29. cell.Font.Bold = true;
  30. cell.ForeColor = System.Drawing.Color.Red;
  31. cell.ColumnSpan = trHeader.Cells.Count;
  32. row.Cells.Add(cell);
  33. tblObj.Rows.Add(row);
  34. }
  35. else
  36. {
  37. for (int i = 0; i < dtObject.Rows.Count; i++)
  38. {
  39. TableRow row = new TableRow();
  40. for (int j = 0; j < trHeader.Cells.Count; i++)
  41. {
  42. TableCell cell = new TableCell();
  43. cell.Text = dtObject.Rows[i][j].ToString();
  44. row.Cells.Add(cell);
  45. }
  46. tblObj.Rows.Add(row);
  47. }
  48. }
  49. }