Как успешно вызвать createDocument через веб-сервис коннектора CMIS Sharepoint? - PullRequest
1 голос
/ 27 января 2012

Я получаю следующую ошибку:

Один или несколько входных параметров для метода службы отсутствуют или недействительны.

при

ObjectService.createDocument (repositoryId, objectPropertyCollection, rootFolderId, myContentStream, ObjectService.enumVersioningState.none, null, addAclcontrol, null, ref extType); вызывается

.Вот как я настроил все эти параметры:

//Get repositoryId, and rootFolder id.
string repositoryId = RepositoryStore[contentType];  
RepositoryService.cmisRepositoryInfoType repoInfo =_controller.RepositoryClient.getRepositoryInfo(repositoryId, new RepositoryService.cmisExtensionType());  
string rootFolder = repoInfo.rootFolderId;  
string theActualName = filename.Substring(filename.LastIndexOf("\\") + 1);  

//Create a cmisContentStreamType.  
ObjectService.cmisContentStreamType fileStream = new ObjectService.cmisContentStreamType();  
fileStream.stream = File.ReadAllBytes(filename);
fileStream.filename = theActualName;
fileStream.length = fileStream.stream.Length.ToString();
fileStream.mimeType = "application/pdf";

//Setting the acl objects needed to create the document. 
ObjectService.cmisAccessControlEntryType homeMembers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType owners = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType viewers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType visitors = new ObjectService.cmisAccessControlEntryType();

ObjectService.cmisAccessControlPrincipalType ownersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
ownersPrincipalType.principalId = @"Home Owners";
owners.principal = ownersPrincipalType;
owners.permission = new string[] { "cmis:all" };
ObjectService.cmisAccessControlPrincipalType homePrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = @"Home Members";
homeMembers.principal = homePrincipalType;
homeMembers.permission = new string[] { "cmis:write" };
ObjectService.cmisAccessControlPrincipalType viewersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = @"Viewers";
homeMembers.principal = viewersPrincipalType;
homeMembers.permission = new string[] { "cmis:read" };
ObjectService.cmisAccessControlPrincipalType visitorsPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = @"Home Visitors";
homeMembers.principal = visitorsPrincipalType;
homeMembers.permission = new string[] { "cmis:read" };

ObjectService.cmisAccessControlEntryType[] addAclControl = new ObjectService.cmisAccessControlEntryType[] { homeMembers, owners, viewers, visitors };

ObjectService.cmisExtensionType exttype = new ObjectService.cmisExtensionType();

ObjectService.cmisPropertiesType objectPropertyArray = MakedocumentPropertiesList(theActualName,fileStream.length);


private ObjectService.cmisPropertiesType MakedocumentPropertiesList(string fileName,string contentStreamLength)
{
List<ObjectService.cmisProperty> arrProps = new List<ObjectService.cmisProperty>();
ObjectService.cmisPropertiesType props = new ObjectService.cmisPropertiesType();

arrProps.Add(GetPropertyString("Name", "cmis:name", "mydocuemntname", "FileLeafRef"));
arrProps.Add(GetPropertyId("cmis:baseTypeId", "cmis:baseTypeId", "cmis:document",   "cmis:baseTypeId"));

props.Items = arrProps.ToArray();

return props;

}

private ObjectService.cmisPropertyString GetPropertyString(string displayName, string    queryName, string value, string localName)
{
ObjectService.cmisPropertyString title = new ObjectService.cmisPropertyString();
title.localName = localName;
title.displayName = displayName;
title.queryName = queryName;
title.propertyDefinitionId = displayName;
title.value = new string[] { value };
return title;
}

private ObjectService.cmisPropertyId GetPropertyId(string displayName, string queryName, string value, string localName)
{
ObjectService.cmisPropertyId id = new  ObjectService.cmisPropertyId();
id.localName = localName;
id.displayName = displayName;
id.queryName = queryName;
id.propertyDefinitionId = displayName;
id.value = new string[] { value };
return id;
}

Ответы [ 2 ]

1 голос
/ 27 января 2012

Вы не можете установить свойство «cmis: baseTypeId», но вы должны установить свойство «cmis: objectTypeId». Попробуйте обменять идентификатор вашего второго свойства.

Кроме того, вы должны взглянуть на DotCMIS . Это может сэкономить вам много работы.

0 голосов
/ 15 марта 2013

Я взял ваш код и исправил его .. теперь он функционирует для меня ... посмотрите:

        string user = txtLogin.Text;
        string password = txtPwd.Text;
        DemoCMISForms.RepositoryService.RepositoryServicePortClient repService = new DemoCMISForms.RepositoryService.RepositoryServicePortClient("BasicHttpBinding_IRepositoryServicePort2");
        repService.ClientCredentials.UserName.UserName = user;
        repService.ClientCredentials.UserName.Password = password;

        DemoCMISForms.ObjectService.ObjectServicePortClient objectService = new DemoCMISForms.ObjectService.ObjectServicePortClient("BasicHttpBinding_IObjectServicePort2");

        objectService.ClientCredentials.UserName.UserName = user;
        objectService.ClientCredentials.UserName.Password = password;

        //Get repositoryId, and rootFolder id.

        RepositoryService.cmisRepositoryInfoType repoInfo = repService.getRepositoryInfo(idRep, new RepositoryService.cmisExtensionType());
        string rootFolder = repoInfo.rootFolderId;
        string theActualName = textBox1.Text.Substring(textBox1.Text.LastIndexOf("\\") + 1);

        //Create a cmisContentStreamType.  
        ObjectService.cmisContentStreamType fileStream = new ObjectService.cmisContentStreamType();
        fileStream.stream = File.ReadAllBytes(textBox1.Text);
        fileStream.filename = theActualName;
        fileStream.length = fileStream.stream.Length.ToString();
        fileStream.mimeType = "text/plain";

        //Setting the acl objects needed to create the document. 
        ObjectService.cmisAccessControlEntryType homeMembers = new ObjectService.cmisAccessControlEntryType();
        ObjectService.cmisAccessControlEntryType owners = new ObjectService.cmisAccessControlEntryType();
        ObjectService.cmisAccessControlEntryType viewers = new ObjectService.cmisAccessControlEntryType();
        ObjectService.cmisAccessControlEntryType visitors = new ObjectService.cmisAccessControlEntryType();

        ObjectService.cmisAccessControlPrincipalType ownersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
        ownersPrincipalType.principalId = @"Home Owners";
        owners.principal = ownersPrincipalType;
        owners.permission = new string[] { "cmis:all" };
        ObjectService.cmisAccessControlPrincipalType homePrincipalType = new ObjectService.cmisAccessControlPrincipalType();
        homePrincipalType.principalId = @"Home Members";
        homeMembers.principal = homePrincipalType;
        homeMembers.permission = new string[] { "cmis:write" };
        ObjectService.cmisAccessControlPrincipalType viewersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
        viewersPrincipalType.principalId = @"Viewers";
        viewers.principal = viewersPrincipalType;
        viewers.permission = new string[] { "cmis:read" };
        ObjectService.cmisAccessControlPrincipalType visitorsPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
        visitorsPrincipalType.principalId = @"Home Visitors";
        visitors.principal = visitorsPrincipalType;
        visitors.permission = new string[] { "cmis:read" };

        ObjectService.cmisAccessControlEntryType[] addAclControl = new ObjectService.cmisAccessControlEntryType[] { homeMembers, owners, viewers, visitors };

        ObjectService.cmisExtensionType exttype = new ObjectService.cmisExtensionType();

        ObjectService.cmisPropertiesType objectPropertyArray = MakedocumentPropertiesList(theActualName, fileStream.length);

        objectService.createDocument(idRep, objectPropertyArray, idFolder, fileStream, ObjectService.enumVersioningState.major, null, addAclControl, null, ref exttype);
    }

    private ObjectService.cmisPropertiesType MakedocumentPropertiesList(string fileName, string contentStreamLength)
    {
        List<ObjectService.cmisProperty> arrProps = new List<ObjectService.cmisProperty>();
        ObjectService.cmisPropertiesType props = new ObjectService.cmisPropertiesType();

        arrProps.Add(GetPropertyString(fileName, "cmis:name", fileName, "FileLeafRef"));
        arrProps.Add(GetPropertyId("cmis:objectTypeId", "cmis:objectTypeId", "cmis:document", "cmis:objectTypeId"));

        props.Items = arrProps.ToArray();

        return props;

    }

    private ObjectService.cmisPropertyString GetPropertyString(string displayName, string queryName, string value, string localName)
    {
        ObjectService.cmisPropertyString title = new ObjectService.cmisPropertyString();
        title.localName = localName;
        title.displayName = displayName;
        title.queryName = queryName;
        title.propertyDefinitionId = displayName;
        title.value = new string[] { value };
        return title;
    }

    private ObjectService.cmisPropertyId GetPropertyId(string displayName, string queryName, string value, string localName)
    {
        ObjectService.cmisPropertyId id = new ObjectService.cmisPropertyId();
        id.localName = localName;
        id.displayName = displayName;
        id.queryName = queryName;
        id.propertyDefinitionId = displayName;
        id.value = new string[] { value };
        return id;
    }

Я нашел некоторые переменные, которые остались неизменными после манипуляции копированием-вставкой!Я также использовал этот пример с текстовым файлом!Надеюсь, я вам помог!

PS: Я еще не справился с проблемой типов документов, я только что сделал пример функционального файла с текстовыми файлами.проблема, поэтому я должен проверить, прежде чем добавить какой-либо документ ..

...