cancel
Showing results for 
Search instead for 
Did you mean: 

Attempting to connect to repository, getting 'DotCMIS.Exceptions.CmisConnectionException' and unsure why.

goebelchase
Champ in-the-making
Champ in-the-making
I am attempting to connect some C# code to an alfresco database, and I have two questions.  Firstly, I am unsure of where to find the 'Repository ID', I have looked at the details page of the repository I need to connect to, but I didn't see anything that seemed to fit the bill.
Additionally, when I run the code below, I get a result of "A first chance exception of type 'DotCMIS.Exceptions.CmisConnectionException' occurred in DotCMIS.dll" but have been unable to find any information about what this message entails.

<blockcode>
try
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters[DotCMIS.SessionParameter.BindingType] = BindingType.AtomPub;
            parameters[DotCMIS.SessionParameter.AtomPubUrl] = "http://localhost:8080/alfresco/service/cmis/index.html";
            parameters[DotCMIS.SessionParameter.User] = "admin";
            parameters[DotCMIS.SessionParameter.Password] = "password";
            parameters[DotCMIS.SessionParameter.RepositoryId] = "<repositoryId>";

            SessionFactory factory = SessionFactory.NewInstance();
            ISession session = factory.CreateSession(parameters);

            IFolder rootFolder = session.GetRootFolder();
            foreach (ICmisObject cmisObject in rootFolder.GetChildren())
            {
                Console.WriteLine(cmisObject.Name);
            }
        }
        catch(Exception ex)
        {
           Console.WriteLine(ex.ToString());
        }
</blockcode>

I thought the error might be due to me leaving a placeholder value for 'RepositoryID', but I'm not sure.
Any help or information you could offer would be very much appreciated.
Thank you in advance.
4 REPLIES 4

kaynezhang
World-Class Innovator
World-Class Innovator
You are using wrong atom url :
for CMIS 1.0, the URL is:

http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.0/atom

for CMIS 1.1, the URL is:

http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom


and you don't need repositoryId parameter, you can write it like follwing

          try
            {
                Dictionary<string, string> parameters = new Dictionary<string, string>();
                parameters[DotCMIS.SessionParameter.BindingType] = BindingType.AtomPub;
                //parameters[DotCMIS.SessionParameter.AtomPubUrl] = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom";
                parameters[DotCMIS.SessionParameter.AtomPubUrl] = "http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.0/atom";
                parameters[DotCMIS.SessionParameter.User] = "admin";
                parameters[DotCMIS.SessionParameter.Password] = "admin";
                //parameters[DotCMIS.SessionParameter.RepositoryId] = "<repositoryId>";

                SessionFactory factory = SessionFactory.NewInstance();
                IList<IRepository> repos = factory.GetRepositories(parameters);
                ISession session = repos.ElementAt(0).CreateSession();

                IFolder rootFolder = session.GetRootFolder();
                foreach (ICmisObject cmisObject in rootFolder.GetChildren())
                {
                    Console.WriteLine(cmisObject.Name);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

Thank you very much, that solved the exception, and I was able to find the repository ID.
Now the only problem is I am getting a 'Object Not Found Exception'.
I believe I need to direct it to the correct folder that contains the files I need to access, rather than the 'root folder', but I don't know what sort of syntax I should use.  Would you be able to help me with this as well?

Edit: Scratch that, it connected correctly once I added the "ISession session = repos.ElementAt(0).CreateSession();" line of code you suggested.  However I am still faced with my original problem of needing to search a specific folder, and I would still appreciate any help you could offer with that.  But it's heartening to know that I am connected successfully.

I am using
<blockcode>
Folder folder = (Folder)session.GetObjectByPath("");

            foreach (ICmisObject cmisObject in folder.GetChildren())
            {
</blockcode>
But I do not know what to enter for the value in 'GetObjectByPath'.  The folder I am attempting to search is called 'Test', and it's on the root folder.  I can search the root folder and see 'Test' in the list, but I do not know what path to enter in order to actually search the 'Test' Folder.
If anyone could help me out with this, I would greatly appreciate it.

kaynezhang
World-Class Innovator
World-Class Innovator
If your "Test" folder is direct under root folder,please write it like this

                IFolder folder1 = (IFolder)session.GetObjectByPath("/Test");