2012-01-27 42 views
1

我收到以下错误:如何通过Sharepoint CMIS连接器webservice成功调用createDocument?

服务方法的一个或多个输入参数丢失或无效。

ObjectService.createDocument(repositoryId,objectPropertyCollection,rootFolderId,myContentStream,ObjectService.enumVersioningState.none,NULL,addAclcontrol,NULL,REF类型),;

被调用。这是我已经设置所有这些参数:

//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; 
} 

回答

1

不能设置“CMIS:baseTypeId”属性,但你必须设置“CMIS:objectTypeId”属性。尝试交换你的第二个属性的ID。

除此之外,你应该看看DotCMIS。它可以为你节省很多工作。

+0

谢谢。这让我朝着正确的方向发展。结束了,只是将cmisPropertyType更改为包含ObjectTypeId信息的两个条目之一,包含文件名的一个cmisPropertyString。 – ascarb 2012-04-12 20:23:59

0

我把你的代码,我纠正它。现在对我来说是功能..看看:

 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; 
    } 

我发现了一个复制粘贴MANIP后保持不变,一些变量!我也用这个例子和一个文本文件! 希望我帮你!

PS:我没有处理文档类型的问题,我只是用文本文件做了示例函数。另外,我从SP网站调用的列表中的版本是一个问题,所以我必须先验证我添加任何文件..